From 43a5b519fdf8e5fb744db287d907bf59bdc5e23f Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Sun, 3 Nov 2024 16:59:23 -0500 Subject: [PATCH] Add API endpoint to get logged in user --- src/auth.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/auth.rs b/src/auth.rs index c0751d1..558bfe2 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -147,6 +147,19 @@ pub async fn get_user() -> Result { auth_session.user.ok_or(ServerFnError::::ServerError("User not logged in".to_string())) } +#[server(endpoint = "get_logged_in_user")] +pub async fn get_logged_in_user() -> Result, ServerFnError> { + let auth_session = extract::>().await + .map_err(|e| ServerFnError::::ServerError(format!("Error getting auth session: {}", e)))?; + + let user = auth_session.user.map(|mut user| { + user.password = None; + user + }); + + Ok(user) +} + /// Check if a user is an admin /// Returns a Result with a boolean indicating if the user is logged in and an admin #[server(endpoint = "check_admin")]