feat(auth): add registration and verification browser flow
This commit is contained in:
1 parent
391af7a1ef
commit
b2322bc178
41 files changed
+2144
-81
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import type { RegistrationDraft } from "../../../features/register-account";
|
||||
|
||||
const storageKey = "lincodex-registration-context";
|
||||
|
||||
export type RegistrationContext = RegistrationDraft & {
|
||||
accepted: boolean;
|
||||
};
|
||||
|
||||
const emptyContext: RegistrationContext = { email: "", scenario: "", accepted: false };
|
||||
|
||||
export function readRegistrationContext(): RegistrationContext {
|
||||
if (typeof window === "undefined") return emptyContext;
|
||||
try {
|
||||
const raw = window.sessionStorage.getItem(storageKey);
|
||||
if (!raw) return emptyContext;
|
||||
const parsed: unknown = JSON.parse(raw);
|
||||
if (typeof parsed !== "object" || parsed === null) return emptyContext;
|
||||
const value = parsed as Record<string, unknown>;
|
||||
const email = typeof value.email === "string" ? value.email : "";
|
||||
const scenario =
|
||||
value.scenario === "candidate" || value.scenario === "employer" ? value.scenario : "";
|
||||
return {
|
||||
email,
|
||||
scenario,
|
||||
accepted: value.accepted === true && email.length > 0 && scenario !== "",
|
||||
};
|
||||
} catch {
|
||||
return emptyContext;
|
||||
}
|
||||
}
|
||||
|
||||
export function writeRegistrationContext(context: RegistrationContext): void {
|
||||
if (typeof window === "undefined") return;
|
||||
try {
|
||||
window.sessionStorage.setItem(storageKey, JSON.stringify(context));
|
||||
} catch {
|
||||
// Registration remains usable when the browser blocks session storage.
|
||||
}
|
||||
}
|
||||
|
||||
export function clearRegistrationContext(): void {
|
||||
if (typeof window === "undefined") return;
|
||||
try {
|
||||
window.sessionStorage.removeItem(storageKey);
|
||||
} catch {
|
||||
// Registration remains usable when the browser blocks session storage.
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user