Skip to content

Commit 429e41f

Browse files
Dan set user (#697)
1 parent a54e81f commit 429e41f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

pgml-dashboard/src/guards.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rocket::request::{FromRequest, Outcome, Request};
55
use rocket::State;
66
use sqlx::PgPool;
77

8+
use crate::models::User;
89
use crate::{Clusters, Context};
910

1011
pub fn default_database_url() -> String {
@@ -46,17 +47,31 @@ impl<'r> FromRequest<'r> for Cluster {
4647
None => -1,
4748
};
4849

49-
let shared_state = match request.guard::<&State<Clusters>>().await {
50+
let user_id: i64 = match cookies.get_private("user_id") {
51+
Some(user_id) => match user_id.value().parse::<i64>() {
52+
Ok(user_id) => user_id,
53+
Err(_) => -1,
54+
},
55+
56+
None => -1,
57+
};
58+
59+
let clusters_shared_state = match request.guard::<&State<Clusters>>().await {
5060
Outcome::Success(pool) => pool,
5161
_ => return Outcome::Forward(()),
5262
};
5363

54-
let pool = shared_state.get(cluster_id);
64+
let pool = clusters_shared_state.get(cluster_id);
5565

5666
let context = Context {
57-
user: shared_state.get_context(cluster_id).user,
58-
cluster: shared_state.get_context(cluster_id).cluster,
59-
visible_clusters: shared_state.get_context(cluster_id).visible_clusters,
67+
user: User {
68+
id: user_id,
69+
email: "".to_string(),
70+
},
71+
cluster: clusters_shared_state.get_context(cluster_id).cluster,
72+
visible_clusters: clusters_shared_state
73+
.get_context(cluster_id)
74+
.visible_clusters,
6075
};
6176

6277
Outcome::Success(Cluster { pool, context })

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy