summary refs log tree commit diff
path: root/src/api/guards/session.rs
diff options
context:
space:
mode:
authorAshelyn Rose <git@ashen.earth>2024-10-26 02:20:32 -0400
committerAshelyn Rose <git@ashen.earth>2024-10-26 02:20:32 -0400
commit130669793dfb77b286a26a373378b4d1f2be837c (patch)
treeb2867473b4610e3f79c3098bf661435c25fcee5c /src/api/guards/session.rs
parent2eee33d2a2042b209dd5f9ef4b7314ea81a33360 (diff)
Very basic rocket db state and session lookup (with hardcoded session id)
Diffstat (limited to 'src/api/guards/session.rs')
-rw-r--r--src/api/guards/session.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/api/guards/session.rs b/src/api/guards/session.rs
new file mode 100644
index 0000000..ccd40a2
--- /dev/null
+++ b/src/api/guards/session.rs
@@ -0,0 +1,25 @@
+use std::str::FromStr;
+
+use rocket::{http::Status, outcome::Outcome, request::{self, Request, FromRequest}};
+use sqlx::PgPool;
+use uuid::Uuid;
+use crate::db::models::auth::LoginSession;
+
+
+#[rocket::async_trait]
+impl<'r> FromRequest<'r> for LoginSession {
+    type Error = ();
+
+    async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
+        // At the moment just always look up this one for initial testing
+        let hardcoded_uuid = "557621dd-b98e-409a-9ce7-25b5004caa42";
+
+        if let Some(db) = req.rocket().state::<PgPool>() {
+            if let Some(session) = LoginSession::lookup(&db, Uuid::from_str(hardcoded_uuid).unwrap()).await {
+                return Outcome::Success(session);
+            }
+        }
+
+        Outcome::Error((Status::InternalServerError, ()))
+    }
+}