Skip to content

feat(studio): opt-in remembered accounts on the sign-in page (#388 step 3) - #390

Merged
Madraka merged 2 commits into
mainfrom
claude/remembered-accounts-388-0f592c
Dec 2, 2026
Merged

Madraka merged 2 commits into
mainfrom
claude/remembered-accounts-388-0f592c

Conversation

@Madraka

@Madraka Madraka commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Refs #388 (step 3)

Base: stacked on #389 (claude/login-guest-388-f4c8e6, steps 1–2), which was still open when this was pushed. Once #389 merges, this rebases onto main and its own commit is the only change.

Opt-in remembered accounts on Studio's signed-out /login, like Cloudflare's login profiles.

What it does

  • Storage (apps/studio/src/lib/remembered-accounts.ts): one versioned localStorage key per origin, cloudhal.rememberedAccounts.v1.
    • Each entry is { email, name, lastUsedAt } and nothing else: no token, session id, role, user id or avatar.
    • At most 5 entries, the oldest dropped. An entry unused for 30 days is dropped on read, and the stored list is rewritten without it.
    • Emails match case-insensitively, with no duplicates. An email over 254 characters is refused; a name is cut to 100 on write, and a stored name over 100 counts as malformed.
    • Every read checks the shape and drops anything malformed (extra keys too). Every access is guarded, so the page works when storage throws, is full or is disabled. now and storage are injectable.
  • Opt-in: in sign-in mode, the form shows a "Remember this account on this device" Checkbox, off by default.
    • After a successful sign-in it saves the email and name from the response.
    • Signing in with an account that is already remembered refreshes its entry, with or without the box. The box is hidden while the typed email is remembered.
    • Sign-up, the setup link and failed sign-ins (which keep their generic error) store nothing.
    • An RFC-0044 sign-in answers without the user, so it falls back to the typed email and keeps the stored name.
  • Chooser: while any entries exist, sign-in mode first shows the new AccountChooser block in @cloudhal/ui, with the description "Choose an account to continue."
    • Each row shows the Avatar, the name and the email. Picking one fills in the email and focuses the password.
    • Each row has a ghost square ✕ "Forget {email} on this device", with a tooltip.
    • "Use another account" shows the empty form.
    • ?redirect= and ?client_id&sig work through the chooser; both are tested.
  • User menu: "Sign out and forget" (UserMinus) sits under "Sign out" while this browser remembers any account.
    • It forgets only the signed-in member's entry, using the email from the cached session (no extra request), then signs out.
    • Plain "Sign out" keeps the entry. No Clear-Site-Data is sent.
  • No changes to /invite, setup-token sign-up or reset-password.

i18n

  • 8 new auth.* keys in en.ts.
  • The other 18 languages are AI drafts written through pnpm i18n:export / pnpm i18n:import. They await review, and no language is marked reviewed.

Docs

  • docs/start/quickstart.md: what is stored and how to remove it.
  • docs/design/DESIGN.md: the auth template (§2) and the AccountChooser row in §6.
  • Changeset for @cloudhal/cli.

Design shots

Taken with pnpm design:shots at 1440 and 390 px against a local cloudhal studio plus Vite. No sideways scroll and no console errors.

  • Without entries: the form gains the unticked opt-in under "Forgot password?".
  • With two entries: the chooser replaces the fields. It aligns with the tabs and buttons, and a long name or email truncates at 390 px.
  • After picking: the email is filled in and the password field has focus. The opt-in is hidden, because the account is remembered already.

Checks

  • Biome on the touched files.
  • pnpm design:lint: 449 files clean.
  • pnpm size:check: ok. LoginPage was split so it stays under 150 lines: useRememberedLogin plus small footer, setup-banner and sign-in-extras components.
  • Studio typecheck.
  • New tests:
    • test/remembered-accounts.test.ts (10)
    • test/login-remembered.test.tsx (14: LoginPage + UserMenu)
    • packages/ui/test/account-chooser.test.tsx (1)
  • Existing login-guest and login-setup tests.
  • The full apps/studio vitest suite: 90 files, 1474 tests passed.

🤖 Generated with Claude Code

Madraka and others added 2 commits December 2, 2026 15:22
A signed-in member who opened /login saw the sign-in form again, and a
signed-out member's deep link was lost after sign-in.

- /login, /forgot-password and /reset-password check the session in
  beforeLoad (the cached one, so no extra request) and go on to the
  validated `redirect`, or to /sites. An RFC-0044 authorization request
  (?client_id=…&sig=…) stays; a playground goes to /sites. /invite is
  unchanged.
- requireSession redirects to /login?redirect=<path+search+hash>. The
  login route keeps `redirect` only when it is a same-origin path
  (lib/login-redirect.ts: one linear pass, at most 2 kB, no `//`, `/\`,
  scheme, backslash or control character). LoginPage goes there after
  sign-in and sign-up; the OAuth `next` URL still wins.
- The session guards move from router.tsx to lib/route-guards.ts.
- The email field says autocomplete="username" in sign-in mode, so
  password managers pair it with the password; sign-up keeps `email`
  and `new-password`.

Tests cover the redirects, the validation (including a 100k-character
value) and that sign-out clears the cached session.

Refs #388 (steps 1–2)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com>
Step 3 of #388, like Cloudflare's login profiles. A "Remember this account
on this device" choice (off by default) keeps { email, name, lastUsedAt }
in localStorage after a successful sign-in: no token, session id, role or
user id; at most five per origin, dropped after 30 days unused, validated
on every read and guarded against storage that throws.

While any are kept, the signed-out /login lists them first (the new
AccountChooser block): picking one fills in the email and focuses the
password, a Forget button removes one, "Use another account" shows the
empty form; ?redirect= and RFC-0044 requests work through it. The user
menu adds "Sign out and forget", which forgets only the signed-in
member's entry. Sign-up, the setup link and failed sign-ins store
nothing; no Clear-Site-Data.

Strings in English; the other languages are AI drafts awaiting review.

Refs #388

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com>
@Madraka
Madraka enabled auto-merge December 2, 2026 12:39
@Madraka
Madraka merged commit 715c3b5 into main Dec 2, 2026
9 checks passed
@Madraka
Madraka deleted the claude/remembered-accounts-388-0f592c branch December 2, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant