Files
Cato ed4288cecd fix(auth): adopt shared account forms and recovery (#51)
* fix(auth): adopt shared account forms and recovery

* fix(auth): use released all-method second-factor protection
2026-10-26 05:34:47 +01:00

34 lines
1.2 KiB
TypeScript

import { returnPath } from "@bitbaum/accountkit/orangecat";
import { routing } from "@/i18n/routing";
import { getPathname } from "@/i18n/navigation";
import { toLocale } from "@/i18n/routing";
import { ROUTES } from "@/lib/routes";
/** The link to the sign-in or sign-up screen, carrying where to come back to. */
export function entryHref(
mode: "sign-in" | "sign-up",
locale: string,
from?: string,
): string {
return getPathname({
href: {
pathname: mode === "sign-up" ? ROUTES.signUp : ROUTES.signIn,
query: from ? { next: from } : {},
},
locale: toLocale(locale),
});
}
/** Localize once, preserving safe callback paths and rejecting auth-page loops. */
export function accountDestination(locale: string, requested?: string) {
const safe = returnPath(requested, ROUTES.matters);
const prefix = new RegExp(`^/(?:${routing.locales.join("|")})(?=/|$)`);
const plain = safe.replace(prefix, "") || "/";
if (/^\/(?:sign-in|sign-up)(?:[/?#]|$)/.test(plain)) {
return getPathname({ href: ROUTES.matters, locale: toLocale(locale) });
}
return prefix.test(safe)
? safe
: getPathname({ href: safe, locale: toLocale(locale) });
}