Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/studio-guest-login.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudhal/cli": patch
---

Studio's `/login`, `/forgot-password` and `/reset-password` no longer show their forms to a signed-in member: they go on to `/sites`, or to the page the member was opening (#388). An MCP client's authorization request (`/login?client_id=…&sig=…`) still shows the sign-in form. A signed-out member who opens a deep link now returns to it after signing in, through `/login?redirect=<path>`, which accepts only paths on Studio's own origin. In sign-in mode the email field is marked `autocomplete="username"`, so password managers offer the saved account.
5 changes: 5 additions & 0 deletions .changeset/studio-remembered-accounts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudhal/cli": patch
---

Studio's sign-in page can remember accounts on a device, like Cloudflare's login profiles (#388). "Remember this account on this device" is off by default; when ticked, a successful sign-in keeps the email, the display name and the time of the sign-in in the browser's `localStorage` (no password, token, session id or role), for at most five accounts per Studio address, each dropped after 30 days unused. The signed-out `/login` then lists them first: picking one fills in the email and focuses the password, ✕ forgets one, and "Use another account" shows the empty form. The account menu adds "Sign out and forget", which forgets the signed-in member's entry and signs out; plain "Sign out" keeps it. The new strings are AI drafts in every language but English, awaiting review.
6 changes: 5 additions & 1 deletion apps/studio/src/components/PasswordField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InputGroup } from "@cloudhal/ui";
import { Eye, EyeSlash } from "@phosphor-icons/react";
import { type KeyboardEvent, useState } from "react";
import { type KeyboardEvent, type Ref, useState } from "react";
import { useT } from "../i18n/index.tsx";

/**
Expand All @@ -17,6 +17,7 @@ export function PasswordField({
autoComplete,
onEnter,
disabled,
inputRef,
}: {
label: string;
description?: string | undefined;
Expand All @@ -26,6 +27,8 @@ export function PasswordField({
autoComplete: "current-password" | "new-password";
onEnter?: (() => void) | undefined;
disabled?: boolean | undefined;
/** The input itself, e.g. to focus it once the login page has filled in a remembered email. */
inputRef?: Ref<HTMLInputElement> | undefined;
}) {
const t = useT();
const [visible, setVisible] = useState(false);
Expand All @@ -38,6 +41,7 @@ export function PasswordField({
disabled={disabled}
>
<InputGroup.Input
ref={inputRef}
type={visible ? "text" : "password"}
value={value}
autoComplete={autoComplete}
Expand Down
72 changes: 72 additions & 0 deletions apps/studio/src/components/RememberedAccounts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { AccountChooser, Button, Checkbox } from "@cloudhal/ui";
import { UserPlus } from "@phosphor-icons/react";
import { useT } from "../i18n/index.tsx";
import { initials } from "../lib/initials.ts";
import type { RememberedAccount } from "../lib/remembered-accounts.ts";

/**
* The signed-out login page's list of accounts remembered on this device (#388 step 3): pick one
* to fill in its email, forget one, or use another account. Words come from the `auth` catalog.
*/
export function RememberedAccountChooser({
accounts,
onChoose,
onForget,
onOther,
}: {
accounts: readonly RememberedAccount[];
onChoose: (email: string) => void;
onForget: (email: string) => void;
onOther: () => void;
}) {
const t = useT();
return (
<div className="grid gap-3" data-testid="remembered-accounts">
<AccountChooser
accounts={accounts.map((a) => ({
email: a.email,
name: a.name,
initials: initials(a.name, a.email),
}))}
onChoose={(a) => onChoose(a.email)}
onForget={(a) => onForget(a.email)}
labels={{
list: t("auth.rememberedAccounts"),
choose: (a) =>
a.name
? t("auth.continueAs", { name: a.name, email: a.email })
: t("auth.continueAsEmail", { email: a.email }),
forget: (a) => t("auth.forgetAccount", { email: a.email }),
}}
/>
<Button
type="button"
variant="secondary"
icon={UserPlus}
className="w-full"
onClick={onOther}
>
{t("auth.useAnotherAccount")}
</Button>
</div>
);
}

/** The opt-in under the sign-in form: off until the member ticks it. */
export function RememberAccountCheckbox({
checked,
onCheckedChange,
}: {
checked: boolean;
onCheckedChange: (checked: boolean) => void;
}) {
const t = useT();
return (
<Checkbox
label={t("auth.rememberAccount")}
checked={checked}
onCheckedChange={(value: boolean) => onCheckedChange(value === true)}
data-testid="remember-account"
/>
);
}
34 changes: 33 additions & 1 deletion apps/studio/src/components/UserMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { Avatar, Button, DropdownMenu, directional, Text, Tooltip } from "@cloudhal/ui";
import { SignOut, SquaresFour, Translate, UserGear, UsersThree } from "@phosphor-icons/react";
import {
SignOut,
SquaresFour,
Translate,
UserGear,
UserMinus,
UsersThree,
} from "@phosphor-icons/react";
import { useNavigate } from "@tanstack/react-router";
import { LOCALES, type Locale, useI18n } from "../i18n/index.tsx";
import { authClient } from "../lib/auth.ts";
import { initials } from "../lib/initials.ts";
import { forgetRememberedAccount, readRememberedAccounts } from "../lib/remembered-accounts.ts";
import { cachedSession } from "../lib/session-cache.ts";
import { useThemePreference } from "../lib/theme.ts";
import {
isMachineTranslated,
Expand Down Expand Up @@ -34,6 +43,13 @@ export function UserMenu() {
await authClient.signOut();
await navigate({ to: "/login" });
};
// #388 step 3: offered while this browser remembers an account; forgets only the member's own.
const remembers = people && readRememberedAccounts().length > 0;
const signOutAndForget = async () => {
const email = await currentEmail();
if (email) forgetRememberedAccount(email);
await signOut();
};
return (
<DropdownMenu>
<Tooltip
Expand Down Expand Up @@ -125,7 +141,23 @@ export function UserMenu() {
{t("common.signOut")}
</DropdownMenu.Item>
)}
{remembers && (
<DropdownMenu.Item icon={UserMinus} onClick={signOutAndForget}>
{t("auth.signOutAndForget")}
</DropdownMenu.Item>
)}
</DropdownMenu.Content>
</DropdownMenu>
);
}

/** The signed-in member's email, from the session kept between navigations (no extra request). */
async function currentEmail(): Promise<string | undefined> {
try {
const session = await cachedSession(async () => (await authClient.getSession()).data);
const email = (session as { user?: { email?: unknown } } | null)?.user?.email;
return typeof email === "string" ? email : undefined;
} catch {
return undefined;
}
}
72 changes: 72 additions & 0 deletions apps/studio/src/components/useRememberedLogin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { useEffect, useRef, useState } from "react";
import {
emailKey,
forgetRememberedAccount,
readRememberedAccounts,
rememberAccount,
touchRememberedAccount,
} from "../lib/remembered-accounts.ts";

/**
* The login page's remembered accounts (#388 step 3): listed first in sign-in mode while any
* exist; picking one hands its email to the page (`onChosen`) and focuses the password; "Use
* another account" shows the empty form; `keep` runs after a successful sign-in.
*/
export function useRememberedLogin({
signingIn,
email,
onChosen,
}: {
signingIn: boolean;
/** The email in the form, to tell whether it is remembered already. */
email: string;
/** Fills in `email` (empty for "Use another account"). */
onChosen: (email: string) => void;
}) {
const [accounts, setAccounts] = useState(() => readRememberedAccounts());
const [choosing, setChoosing] = useState(true);
const [remember, setRemember] = useState(false);
const [focusPassword, setFocusPassword] = useState(false);
const passwordRef = useRef<HTMLInputElement>(null);
useEffect(() => {
if (!focusPassword) return;
passwordRef.current?.focus();
setFocusPassword(false);
}, [focusPassword]);

return {
accounts,
showChooser: signingIn && choosing && accounts.length > 0,
/** The typed email is remembered already: no opt-in shown, and sign-in refreshes it. */
remembered: accounts.some((a) => emailKey(a.email) === emailKey(email)),
remember,
setRemember,
passwordRef,
choose(chosen: string) {
onChosen(chosen);
setChoosing(false);
setFocusPassword(true);
},
forget(forgotten: string) {
setAccounts(forgetRememberedAccount(forgotten));
},
useAnother() {
onChosen("");
setChoosing(false);
},
/**
* After a successful sign-in: remember the account when the member asked to, or refresh it
* when it is remembered already. The email and name come from the response, else the typed
* email (an OAuth sign-in answers with where to go, without the user).
*/
keep(data: unknown, typed: string) {
const user = (data as { user?: { email?: unknown; name?: unknown } } | null)?.user;
const account = {
email: typeof user?.email === "string" ? user.email : typed,
name: typeof user?.name === "string" ? user.name : undefined,
};
if (remember) rememberAccount(account);
else touchRememberedAccount(account);
},
};
}
10 changes: 9 additions & 1 deletion apps/studio/src/i18n/ar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Generated by `pnpm i18n:import` (ADR-0034): ar core messages.
// Do not edit: change the translation file and import it; only English is edited here.
// hash: 830eafd5ee91d95b
// hash: 73c0e0a127fdc76c
import type { Messages } from "./en.ts";

export const messages: Messages = {
Expand Down Expand Up @@ -77,6 +77,14 @@ export const messages: Messages = {
setupTitle: "إعداد هذا الـStudio",
setupDescription:
"فتحت رابط الإعداد الذي ظهر عند تشغيل Cloudhal أو نشره. الحساب الذي تنشئه الآن يصبح المالك؛ وبعد ذلك يُغلق التسجيل.",
rememberAccount: "تذكّر هذا الحساب على هذا الجهاز",
chooseAccount: "اختر حسابًا للمتابعة.",
rememberedAccounts: "الحسابات المحفوظة",
continueAs: "المتابعة باسم {name} ({email})",
continueAsEmail: "المتابعة باسم {email}",
forgetAccount: "انسَ {email} على هذا الجهاز",
useAnotherAccount: "استخدم حسابًا آخر",
signOutAndForget: "تسجيل الخروج ونسيان الحساب",
},
sites: {
title: "المواقع",
Expand Down
10 changes: 9 additions & 1 deletion apps/studio/src/i18n/de.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Generated by `pnpm i18n:import` (ADR-0034): de core messages.
// Do not edit: change the translation file and import it; only English is edited here.
// hash: e7b7c6e7401e9d7f
// hash: f4b3c7b2495df788
import type { Messages } from "./en.ts";

export const messages: Messages = {
Expand Down Expand Up @@ -78,6 +78,14 @@ export const messages: Messages = {
setupTitle: "Dieses Studio einrichten",
setupDescription:
"Du hast den Einrichtungslink geöffnet, den Cloudhal beim Start oder beim Deployment ausgegeben hat. Das Konto, das du jetzt erstellst, wird Inhaber; danach ist die Registrierung geschlossen.",
rememberAccount: "Dieses Konto auf diesem Gerät merken",
chooseAccount: "Wähle ein Konto, um fortzufahren.",
rememberedAccounts: "Gemerkte Konten",
continueAs: "Weiter als {name} ({email})",
continueAsEmail: "Weiter als {email}",
forgetAccount: "{email} auf diesem Gerät vergessen",
useAnotherAccount: "Anderes Konto verwenden",
signOutAndForget: "Abmelden und vergessen",
},
sites: {
title: "Websites",
Expand Down
16 changes: 16 additions & 0 deletions apps/studio/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ export const en = {
setupTitle: "Set up this Studio",
setupDescription:
"You opened the setup link printed when Cloudhal started or was deployed. The account you create now becomes the owner; afterwards sign-up closes.",
/** Checkbox under the sign-in form, off by default: keeps the email and name in this browser for the account list. */
rememberAccount: "Remember this account on this device",
/** Description over the list of accounts remembered on this device. */
chooseAccount: "Choose an account to continue.",
/** Accessible name of the list of remembered accounts. */
rememberedAccounts: "Remembered accounts",
/** Accessible name of a remembered account's row. */
continueAs: "Continue as {name} ({email})",
/** Accessible name of a remembered account's row when it has no name. */
continueAsEmail: "Continue as {email}",
/** Icon button beside a remembered account: removes it from this browser's list. */
forgetAccount: "Forget {email} on this device",
/** Button under the list of remembered accounts: shows the empty sign-in form. */
useAnotherAccount: "Use another account",
/** Account menu item: removes the member from this browser's remembered accounts, then signs out. */
signOutAndForget: "Sign out and forget",
},
sites: {
title: "Sites",
Expand Down
10 changes: 9 additions & 1 deletion apps/studio/src/i18n/es.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Generated by `pnpm i18n:import` (ADR-0034): es core messages.
// Do not edit: change the translation file and import it; only English is edited here.
// hash: ae3c6dd87f980d83
// hash: bb0013fa0505bc01
import type { Messages } from "./en.ts";

export const messages: Messages = {
Expand Down Expand Up @@ -77,6 +77,14 @@ export const messages: Messages = {
setupTitle: "Configura este Studio",
setupDescription:
"Abriste el enlace de configuración que Cloudhal mostró al iniciarse o al desplegarse. La cuenta que crees ahora será la propietaria; después se cierra el registro.",
rememberAccount: "Recordar esta cuenta en este dispositivo",
chooseAccount: "Elige una cuenta para continuar.",
rememberedAccounts: "Cuentas recordadas",
continueAs: "Continuar como {name} ({email})",
continueAsEmail: "Continuar como {email}",
forgetAccount: "Olvidar {email} en este dispositivo",
useAnotherAccount: "Usar otra cuenta",
signOutAndForget: "Cerrar sesión y olvidar",
},
sites: {
title: "Sitios",
Expand Down
10 changes: 9 additions & 1 deletion apps/studio/src/i18n/fa.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Generated by `pnpm i18n:import` (ADR-0034): fa core messages.
// Do not edit: change the translation file and import it; only English is edited here.
// hash: cbba59c8a0333652
// hash: c1245b3a22530500
import type { Messages } from "./en.ts";

export const messages: Messages = {
Expand Down Expand Up @@ -77,6 +77,14 @@ export const messages: Messages = {
setupTitle: "راه‌اندازی این Studio",
setupDescription:
"شما پیوند راه‌اندازی‌ای را باز کرده‌اید که Cloudhal هنگام اجرا یا استقرار نشان داد. حسابی که اکنون می‌سازید مالک می‌شود؛ پس از آن ثبت‌نام بسته می‌شود.",
rememberAccount: "این حساب را در این دستگاه به خاطر بسپار",
chooseAccount: "برای ادامه، یک حساب انتخاب کنید.",
rememberedAccounts: "حساب‌های به‌خاطرسپرده",
continueAs: "ادامه به‌عنوان {name} ({email})",
continueAsEmail: "ادامه به‌عنوان {email}",
forgetAccount: "فراموش کردن {email} در این دستگاه",
useAnotherAccount: "استفاده از حساب دیگر",
signOutAndForget: "خروج و فراموش کردن",
},
sites: {
title: "سایت‌ها",
Expand Down
10 changes: 9 additions & 1 deletion apps/studio/src/i18n/fr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Generated by `pnpm i18n:import` (ADR-0034): fr core messages.
// Do not edit: change the translation file and import it; only English is edited here.
// hash: 2165aa26fabf49d8
// hash: 0735a5147eb170e3
import type { Messages } from "./en.ts";

export const messages: Messages = {
Expand Down Expand Up @@ -77,6 +77,14 @@ export const messages: Messages = {
setupTitle: "Configurer ce Studio",
setupDescription:
"Vous avez ouvert le lien de configuration affiché par Cloudhal à son démarrage ou à son déploiement. Le compte que vous créez maintenant en devient le propriétaire ; les inscriptions se ferment ensuite.",
rememberAccount: "Se souvenir de ce compte sur cet appareil",
chooseAccount: "Choisissez un compte pour continuer.",
rememberedAccounts: "Comptes mémorisés",
continueAs: "Continuer en tant que {name} ({email})",
continueAsEmail: "Continuer en tant que {email}",
forgetAccount: "Oublier {email} sur cet appareil",
useAnotherAccount: "Utiliser un autre compte",
signOutAndForget: "Se déconnecter et oublier",
},
sites: {
title: "Sites",
Expand Down
3 changes: 3 additions & 0 deletions apps/studio/src/i18n/generated/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ export interface MessageParams {
"articleTerms.requiredToast": { singular: string | number };
"articles.facets.allCategories": { label: string | number };
"articles.facets.allTags": { label: string | number };
"auth.continueAs": { name: string | number; email: string | number };
"auth.continueAsEmail": { email: string | number };
"auth.forgetAccount": { email: string | number };
"bodyEditor.focusShortcut": { keys: string | number };
"build.activity.changed": { count: number };
"build.activity.operations": { count: string | number };
Expand Down
Loading