mirror of
https://github.com/bitbaum/heidi.git
synced 2026-12-04 08:38:28 +01:00
* wip(accounts): Heidi on @bitbaum/accountkit/auth (accountkit pin pending) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QDMxjTqKNLXETMYYuapMa3 * feat(accounts): Heidi has its own accounts; OrangeCat is one way in, not the only one Email and password, passkeys and two-step codes from @bitbaum/accountkit/auth, with the shared screens in Heidi's seven languages. People whose first way in was OrangeCat keep their actor id, so no row moves. next-auth removed; the session secret falls back to the existing AUTH_SECRET. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QDMxjTqKNLXETMYYuapMa3 --------- Co-authored-by: Claude <noreply@anthropic.com>
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { DEFAULT_LOCALE, LOCALES, type Locale } from "../i18n/locales.ts";
|
|
|
|
/**
|
|
* The sign-in page for a return path. The return path may itself be a route
|
|
* that applies the saved language first (`/api/account/language?next=/de/…`),
|
|
* so the language of the sign-in page is read from the innermost path.
|
|
*/
|
|
export function signInPath(returnTo: string): string {
|
|
return `/${localeIn(returnTo)}/sign-in?next=${encodeURIComponent(safeReturn(returnTo))}`;
|
|
}
|
|
|
|
export function localeIn(path: string): Locale {
|
|
let decoded = path;
|
|
try {
|
|
decoded = decodeURIComponent(path);
|
|
} catch {
|
|
// keep it as written
|
|
}
|
|
const match = decoded.match(/\/([a-z]{2,3})(?:\/|$|\?)/g) ?? [];
|
|
for (const m of match) {
|
|
const code = m.replace(/[/?]/g, "");
|
|
if ((LOCALES as readonly string[]).includes(code)) return code as Locale;
|
|
}
|
|
return DEFAULT_LOCALE;
|
|
}
|
|
|
|
/** A path on this site, or the home page: a sign-in link must never be an open redirect. */
|
|
export function safeReturn(value: string | null | undefined, fallback = "/de"): string {
|
|
if (!value || !value.startsWith("/") || value.startsWith("//") || value.includes("\\")) return fallback;
|
|
return value;
|
|
}
|