From f6fb736ff775cfcf0d7fda1d29f9c3d7b27ed3c9 Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Sat, 26 Aug 2023 05:47:38 -0400 Subject: [PATCH] Add log-out route (necessary to delete secret cookie) --- server/src/api/auth.rs | 6 ++++++ server/src/api/mod.rs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/server/src/api/auth.rs b/server/src/api/auth.rs index 29de90d..415a122 100644 --- a/server/src/api/auth.rs +++ b/server/src/api/auth.rs @@ -69,6 +69,12 @@ pub(super) async fn sign_up( Ok(()) } +#[delete("/")] +pub(super) async fn sign_out(cookies: &CookieJar<'_>) { + cookies.remove_private(Cookie::named("user")); + cookies.remove(Cookie::named("name")); +} + /// Authentication guard #[derive(Deref)] pub(super) struct Auth(users::Model); diff --git a/server/src/api/mod.rs b/server/src/api/mod.rs index 584d78e..eaae998 100644 --- a/server/src/api/mod.rs +++ b/server/src/api/mod.rs @@ -114,7 +114,7 @@ pub fn start_server(db: DatabaseConnection) -> Rocket { "/api/v1/groups", routes![all_groups, group, insert_group, update_group, delete_group], ) - .mount("/api/v1/auth", routes![auth::login, auth::sign_up]) + .mount("/api/v1/auth", routes![auth::login, auth::sign_up, auth::sign_out]) .mount("/", FileServer::from("/src/public")); #[cfg(feature = "unsafe_import")]