From 79903c779a4c6726285fbd993cd8fca6e49acdb1 Mon Sep 17 00:00:00 2001 From: dannyzou18 Date: Fri, 12 Apr 2024 19:48:39 -0400 Subject: [PATCH] added a logout button --- src/components/personal.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/components/personal.rs b/src/components/personal.rs index 0f8132c..5c7b76a 100644 --- a/src/components/personal.rs +++ b/src/components/personal.rs @@ -2,8 +2,6 @@ use leptos::leptos_dom::*; use leptos::*; use leptos_icons::*; -use crate::auth::check_auth; - #[component] pub fn Personal(logged_in: ReadSignal) -> impl IntoView { view! { @@ -32,7 +30,7 @@ pub fn Profile(logged_in: ReadSignal) -> impl IntoView { when=move || {logged_in() == true} fallback=move || view!{} > -

Hello

+ @@ -49,3 +47,26 @@ pub fn DropDownNotLoggedIn() -> impl IntoView { } } +#[component] +pub fn DropDownLoggedIn() -> impl IntoView { + use crate::auth::logout; + + let logout = move |_ev: leptos::ev::MouseEvent| { + spawn_local(async move { + let _logout_result = logout().await; + if let Err(err) = _logout_result { + log!("Error logging out: {:?}", err); + } else { + log!("Logged out Successfully!"); + leptos_router::use_navigate()("/login", Default::default()); + } + + }); + }; + view! { + + } +} \ No newline at end of file