From fa7b98e9c94b775a47341c4097c6e6451c887886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 31 Aug 2026 06:48:48 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(accounts):=20claiming,=20red?= =?UTF-8?q?eeming=20and=20changing=20a=20password=20count=20as=20a=20last?= =?UTF-8?q?=20seen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/izlek-core/src/accounts.rs | 17 +++++++++++++++++ crates/izlek-core/tests/store.rs | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/crates/izlek-core/src/accounts.rs b/crates/izlek-core/src/accounts.rs index af922ad..a79e07f 100644 --- a/crates/izlek-core/src/accounts.rs +++ b/crates/izlek-core/src/accounts.rs @@ -127,6 +127,16 @@ impl Accounts { Err(StoreError::AlreadyClaimed) => return Err(AccountError::AlreadyClaimed), Err(e) => return Err(e.into()), }; + // The claim is the admin's first arrival; it counts as their last + // seen, or their own page reads "active" under "last seen". + self.store + .mark_signed_in(&admin.id, OffsetDateTime::now_utc()) + .await?; + let admin = self + .store + .user(&admin.id) + .await? + .ok_or(StoreError::NotFound)?; let signed_in = self.start_session(admin).await?; Ok((workspace, signed_in)) } @@ -297,6 +307,9 @@ impl Accounts { } self.store.set_password_hash(&user.id, &hash).await?; + // Choosing the password is their first arrival; it counts as their + // last seen, or their own page reads "active" under "last seen". + self.store.mark_signed_in(&user.id, now).await?; self.store.clear_auth_attempts(&client_bucket).await?; let user = self .store @@ -395,6 +408,10 @@ impl Accounts { auth::check_password(new, &user.email, &user.display_name)?; let hash = hash_password(new)?; self.store.set_password_hash(&user.id, &hash).await?; + // Changing the password is presence; it counts as their last seen. + self.store + .mark_signed_in(&user.id, OffsetDateTime::now_utc()) + .await?; self.store.clear_auth_attempts(&client_bucket).await?; // "Signs out your other devices", as the pane promises. self.store diff --git a/crates/izlek-core/tests/store.rs b/crates/izlek-core/tests/store.rs index 3be28a7..3b60098 100644 --- a/crates/izlek-core/tests/store.rs +++ b/crates/izlek-core/tests/store.rs @@ -1685,6 +1685,10 @@ async fn claiming_makes_an_admin_and_signs_them_in() { .unwrap(); assert_eq!(workspace.name, "İzlek"); assert_eq!(signed_in.user.role, Role::Admin); + assert!( + signed_in.user.last_signed_in_at.is_some(), + "the claim is their first arrival" + ); // The cookie value works and is not what is stored. let who = accounts @@ -1759,6 +1763,10 @@ async fn an_invited_member_chooses_their_own_password() { .unwrap(); assert_eq!(signed_in.user.id, invitation.user.id); assert!(signed_in.user.has_signed_in()); + assert!( + signed_in.user.last_signed_in_at.is_some(), + "redeeming the link is their first arrival" + ); // And now the password they chose works, and only that one. accounts @@ -2224,6 +2232,16 @@ async fn changing_a_password_signs_out_every_device() { .is_some() ); + // The baseline is read from the store, not from `second`: sign_in hands + // back the user it fetched before marking, one arrival stale. + let seen = accounts + .store() + .user(&admin.id) + .await + .unwrap() + .unwrap() + .last_signed_in_at + .unwrap(); let fresh = accounts .change_password( &admin.id, @@ -2233,6 +2251,10 @@ async fn changing_a_password_signs_out_every_device() { ) .await .unwrap(); + assert!( + fresh.user.last_signed_in_at.unwrap() > seen, + "changing the password is presence" + ); for old in [&first, &second] { assert!(