Repository navigation
Description
What happens
A signed-in member who opens /login in Studio (for example from a bookmark, the browser history or a typed URL) sees the sign-in form again, with its "Create account" tab. Reproduced on studio.cloudhal.com on 2026-12-02: /api/auth/get-session returns a session, and /login still shows the form.
A related problem: when a signed-out member opens a deep link (such as /sites/<site>/entries/<id>), requireSession redirects to /login without remembering the target. After sign-in, LoginPage always goes to /sites, so the link the member opened is lost.
Why
apps/studio/src/router.tsx:loginRoutehas nobeforeLoad, so nothing checks for a session. Only the protected routes (requireSession) do.requireSessionthrowsredirect({ to: "/login" })without the target, andLoginPage.submitthen callsnavigate({ to: "/sites" }).
What it should do
Studio should treat /login as a guest-only route, like most admin consoles and TanStack Router's authenticated-routes example:
-
Signed in → leave
/login.loginRoute.beforeLoadchecks the session withcachedSession(no extra request when one is cached) and redirects to the requested target if there is one, otherwise to/sites.- Exceptions:
- An RFC-0044 authorization request (
?client_id=…&sig=…) stays on the page, so the provider can still ask for sign-in again when it wants to. - A playground has no sign-in (RFC-0036 §5), so it goes to
/sites.
- An RFC-0044 authorization request (
/forgot-passwordand/reset-passwordget the same check./invitedoes not: it accepts an invite for the signed-in member too.
- Exceptions:
-
Signed out → come back after sign-in.
requireSessionredirects withsearch: { redirect: location.href }.loginRoute.validateSearchacceptsredirectonly if it is a same-origin path, so it cannot become an open redirect:- it must start with
/; - it must not start with
//or/\; - it must have no scheme;
- it must be at most 2 kB.
After sign-in (and after sign-up),
LoginPagegoes there instead of/sites. - it must start with
-
Sign-out still clears the cached session (
forgetSession) before going to/login, so the new check never bounces a member who has just signed out.
Tests
- Router: with a session,
/loginredirects to/sites. - Router: with a session,
/login?redirect=/sites/aredirects to/sites/a. - Router: with a session,
/login?client_id=x&sig=ydoes not redirect. - Router: without a session, a protected deep link redirects to
/login?redirect=<path>. redirectvalidation, which must reject://evil.example/\evil.examplehttps://evil.examplejavascript:…- a 100k-character value (hard rule 13)
LoginPage: after sign-in it goes to the validatedredirect.- Sign-out followed by
/login: the form shows (cache cleared).
Research: remembered and multiple accounts (2026-12-02)
The question: should a signed-out /login offer the last account used (like Cloudflare), or should one browser hold several signed-in accounts with a switcher (like GitHub or Google)?
How others do it
| Product | What is shown | Where it is kept | How it is removed |
|---|---|---|---|
| Cloudflare dashboard (changelog 2026-08-21) | Opt-in "login profile", offered after sign-in: email, method and which was used last; up to 5 per device; picking one prefills the email or resumes SSO | in the browser | removed from the list on the login page |
| GitHub (changelog 2023-11-03, docs) | several signed-in accounts and a switcher; switching needs no new sign-in until a session expires | browser sessions | "Remove" per account, "Sign out from all accounts" |
| Google (help) | account chooser; signed-out accounts stay listed | browser | "Remove an account", in each browser |
Clerk (2025-09-12), Better Auth last-login-method |
a "last used" badge on the method only (Google, email…) | cookie or client state | expires (Better Auth: 30 days) |
Security rules that apply
- Opt-in. A remembered email shows who used this browser to anyone who sits down at it next, so it is kept only when the member asks. The login page offers "Not you? Forget" and keeps failed sign-ins generic, so they do not reveal whether an account exists (OWASP Authentication).
- Not a credential, not in an auth cookie. It holds the email and display name only: never a token, a session id or a role. Session tokens stay in HttpOnly cookies (OWASP Session Management, NIST SP 800-63B-4 §5.1).
localStorageis acceptable for this; OWASP's web-storage warning is about tokens. - Bounded. At most 5 entries, each forgotten after 30 days without a sign-in, and cleared by "Forget" or by "Sign out and forget". Normal sign-out does not send
Clear-Site-Data: "storage", which would wipe it too. - Several sessions must be visible and revocable per account. Studio already lists sessions and revokes the others (
AccountPage).
Better Auth 1.7
multi-session:- up to 5 sessions per device;
- one signed cookie per account,
<session>_multi-<token>; - endpoints
list-device-sessions,set-activeandrevoke. - Sign-out ends every session on the browser, not only the active one.
- CVE-2025-71402 (unsigned
_multi-cookies on sign-out) was fixed in 1.4.0.
last-login-method:- stores the method only, in a non-HttpOnly cookie, for 30 days;
- with email and password as the only method, it would always say "email".
Cloudhal's own constraints
- One organization per deployment (RFC-0005 §11). Two staff accounts in one Studio are rare; a switcher helps mostly someone testing roles.
- Switching changes the cookie for every tab. Studio keeps the session for 5 minutes (
lib/session-cache.ts), and the API caches it in a cookie for 60 s. A second tab would go on showing account A while its writes run as account B: the wrong author in the audit log and the wrong role for the screen. A switcher would need every tab to reload on switch (aBroadcastChannel) and a check that the session cache and the cookie cache follow at once. - Field hint. The email field uses
autoComplete="email"in sign-in mode. Password managers pair the identifier and password more reliably withusername(and laterusername webauthn).
Proposal
- This issue: the guest-only
/loginand the kept deep link. As described above. - Same PR: field hints. Sign-in uses
autoComplete="username"; sign-up keepsemailandnew-password. The browser's password manager then offers the last used account, and Studio stores nothing. - Follow-up: opt-in remembered accounts, like Cloudflare.
- After a sign-in, a "Remember this account on this device" choice. It is off by default and never shown in a playground.
- Up to 5 entries in
localStorage. Each holds the email, the display name and the last-used time; no avatar request, no token. - The signed-out
/loginlists them. Picking one prefills the email and focuses the password field. - Each entry has "Forget", and the user menu adds "Sign out and forget".
- Entries expire after 30 days unused, and each Studio origin keeps its own.
- All copy goes through
useT()in every language.
- Later, with an RFC: passkeys with autofill (Better Auth
passkey,signIn.passkey({ autoFill: true })). This is the modern form of "last used account": the browser offers the account, and there is no password to type. It needs new tables, so it is a contract change.last-login-methodbecomes useful then. - Deferred: several signed-in accounts (
multi-session). Revisit when one Studio serves several organizations (the hosted Cloud). That work needs the reload across tabs, per-account Remove next to "Sign out of all accounts", and an audit review.
🤖 Generated with Claude Code
Activity
Merge pull request #389 from cloudhal-dev/claude/login-guest-388-f4c8e6
feat(studio): opt-in remembered accounts on the sign-in page (#388)
Merge pull request #390 from cloudhal-dev/claude/remembered-accounts-…
Madraka commentedon Dec 3, 2026
Done for this issue's scope, shipped in 0.12.0:
/login,/forgot-passwordand/reset-password. The RFC-0044client_id+sigexception and the playground exception are kept. Deep links are kept through a validated?redirect=. Sign-in usesautoComplete="username".Proposal steps 4 (passkeys, which needs an RFC) and 5 (
multi-session, deferred) move to 395.Madraka commentedon Dec 3, 2026
Follow-up issue: #395