From 3836ec344238d14c6e35e8f8cf0b32ee4ae2a0f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 26 Aug 2026 16:07:40 +0300 Subject: [PATCH] :sparkles: feat(settings): there is a way to sign out MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The server function has existed since the auth slice; nothing in the interface ever called it, so the only way to end a session was to wait a fortnight for it to expire or clear the cookie by hand. On a shared machine that is not a missing button, it is a missing lock. It sits in the profile panel, which is the panel about you, under a line saying what it does and does not do — this browser ends, your other ones do not. The call now answers with a redirect home rather than a value, because there is nothing left to say to the page that asked: every panel on it is about somebody who is no longer signed in. Home with no session is the sign-in page, so a browser without script lands where a hydrated one does instead of sitting on a page that appears not to have reacted. Tested at the endpoint: the cookie stops working on the server after the call, the no-script post answers `302 /`, and one person signing out leaves everybody else's session alone. --- crates/dizey-web/src/auth.rs | 7 +++ crates/dizey-web/src/settings.rs | 11 +++++ crates/dizey-web/tests/http.rs | 81 ++++++++++++++++++++++++++++++++ style/main.scss | 20 ++++++++ 4 files changed, 119 insertions(+) diff --git a/crates/dizey-web/src/auth.rs b/crates/dizey-web/src/auth.rs index 72ddd3a..9175db7 100644 --- a/crates/dizey-web/src/auth.rs +++ b/crates/dizey-web/src/auth.rs @@ -423,6 +423,12 @@ pub async fn sign_in(email: String, password: String) -> Result, } /// Ends this browser's session. Other browsers keep theirs. +/// +/// The answer is a redirect home rather than a value, because there is nothing +/// left to say to the page that asked: whoever was signed in is not any more, +/// and every panel on it is about them. Home with no session is the sign-in +/// page, so both a hydrated browser and one without script land in the same +/// place, which is the one that makes sense. #[server] pub async fn sign_out() -> Result<(), ServerFnError> { use crate::server::{accounts, clear_session_cookie, presented_session}; @@ -431,6 +437,7 @@ pub async fn sign_out() -> Result<(), ServerFnError> { let _ = accounts().sign_out(&presented).await; } clear_session_cookie(); + leptos_axum::redirect("/", false); Ok(()) } diff --git a/crates/dizey-web/src/settings.rs b/crates/dizey-web/src/settings.rs index 9c6d935..fc3a653 100644 --- a/crates/dizey-web/src/settings.rs +++ b/crates/dizey-web/src/settings.rs @@ -547,6 +547,7 @@ fn SettingsScreen( #[component] fn ProfilePanel(me: Me) -> impl IntoView { let action = ServerAction::::new(); + let out = ServerAction::::new(); let value = action.value(); let saved = move || matches!(value.get(), Some(Ok(None))); let refusal = move || match value.get() { @@ -592,6 +593,16 @@ fn ProfilePanel(me: Me) -> impl IntoView { +
+ + "Signing out ends this browser's session. Anywhere else you are signed in stays signed in." + + + + +
} } diff --git a/crates/dizey-web/tests/http.rs b/crates/dizey-web/tests/http.rs index 06cd579..7c1bd3e 100644 --- a/crates/dizey-web/tests/http.rs +++ b/crates/dizey-web/tests/http.rs @@ -1485,3 +1485,84 @@ async fn an_invitation_names_the_admin_who_made_it_and_not_the_invitee() { answer.body ); } + +/// Signing out ends the session on the server, not merely in the browser. A +/// cookie that survived in a copied header, a bookmarked tab or a shared +/// machine must stop working the moment the button is pressed. +#[tokio::test] +async fn signing_out_stops_the_session_being_worth_anything() { + let app = App::open().await; + let cookie = admin(&app).await; + + let works = app + .post( + path::(), + Some(&cookie), + &[], + ) + .await; + assert!(works.body.contains("administers"), "{}", works.body); + + let out = app + .post(path::(), Some(&cookie), &[]) + .await; + assert_eq!(out.status, StatusCode::OK, "{}", out.body); + + // The same cookie, replayed. The server has to be the one refusing. + let after = app + .post( + path::(), + Some(&cookie), + &[], + ) + .await; + assert!( + !after.body.contains("administers"), + "the session outlived signing out: {}", + after.body + ); +} + +/// A browser with no script is sent home, where no session means the sign-in +/// page. Without this the click looks like nothing happening on the very page +/// that is now about nobody. +#[tokio::test] +async fn signing_out_without_script_lands_on_the_sign_in_page() { + let app = App::open().await; + let cookie = admin(&app).await; + + let out = app + .post_without_script( + path::(), + Some(&cookie), + "http://dizey.test/settings", + &[], + ) + .await; + + assert_eq!(out.status, StatusCode::FOUND, "{}", out.body); + assert_eq!(out.location.as_deref(), Some("/"), "{:?}", out.location); +} + +/// Signing out is not a way to sign anybody else out. The other person's +/// session is untouched, and so is every other browser of the person leaving. +#[tokio::test] +async fn signing_out_leaves_every_other_session_alone() { + let app = App::open().await; + let admin_cookie = admin(&app).await; + let member = invited(&app, &admin_cookie, "emre@dizey.sh", "Emre", Role::Member).await; + + let out = app + .post(path::(), Some(&member), &[]) + .await; + assert_eq!(out.status, StatusCode::OK, "{}", out.body); + + let still = app + .post( + path::(), + Some(&admin_cookie), + &[], + ) + .await; + assert!(still.body.contains("administers"), "{}", still.body); +} diff --git a/style/main.scss b/style/main.scss index 888a13c..8b30011 100644 --- a/style/main.scss +++ b/style/main.scss @@ -1575,6 +1575,26 @@ a { align-items: center; gap: 12px; justify-content: flex-end; + + // A foot with something to say on the left and the button on the right. + &-split { justify-content: space-between; } +} + +// The quiet counterpart of `.primary`, for an action that is real but is not +// what the panel is for — signing out of a panel about your name, say. +.quiet { + height: 36px; + padding: 0 16px; + background: transparent; + border: 1px solid var(--border-strong); + border-radius: var(--radius); + color: var(--ink); + font-family: var(--font-sans); + font-size: 13px; + font-weight: 600; + cursor: pointer; + + &:hover { background: #f1efe8; } } .field {