feat(auth): add registration and verification browser flow

This commit is contained in:
TakuyaYagam1 committed 2026-10-07 13:02:16 +03:00
1 parent 391af7a1ef
commit b2322bc178
41 files changed
+2144 -81

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
export { LoginPage } from "./ui/login-page";
export { RegisterPage } from "./ui/register-page";
export { VerifyEmailPage } from "./ui/verify-email-page";
@@ -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.
}
}
+26
View File
@@ -0,0 +1,26 @@
import { useCallback, useState } from "react";
import { ResendVerificationForm } from "../../../features/resend-email-verification";
import { SignInForm } from "../../../features/sign-in";
import { Page, Section } from "../../../shared/ui";
import { clearRegistrationContext } from "../model/registration-context";
export function LoginPage() {
const [unverifiedEmail, setUnverifiedEmail] = useState("");
const clearPendingRegistration = useCallback(() => {
setUnverifiedEmail("");
clearRegistrationContext();
}, []);
return (
<Page title="Вход" lead="Войдите, чтобы продолжить настройку аккаунта с сохраненного шага.">
<Section title="Войти в аккаунт">
<SignInForm onUnverified={setUnverifiedEmail} onSignedIn={clearPendingRegistration} />
</Section>
{unverifiedEmail ? (
<Section title="Повторная отправка письма">
<ResendVerificationForm initialEmail={unverifiedEmail} />
</Section>
) : null}
</Page>
);
}
@@ -0,0 +1,68 @@
import { useState } from "react";
import { RegisterForm, type RegistrationDraft } from "../../../features/register-account";
import { ResendVerificationForm } from "../../../features/resend-email-verification";
import { Button, Page, Section, TextLink } from "../../../shared/ui";
import { paths } from "../../../shared/config";
import {
clearRegistrationContext,
readRegistrationContext,
writeRegistrationContext,
type RegistrationContext,
} from "../model/registration-context";
function scenarioLabel(scenario: RegistrationDraft["scenario"]): string {
return scenario === "employer" ? "работодатель" : "кандидат";
}
export function RegisterPage() {
const [context, setContext] = useState<RegistrationContext>(readRegistrationContext);
function saveDraft(draft: RegistrationDraft) {
const next = { ...draft, accepted: false };
setContext(next);
writeRegistrationContext(next);
}
function markAccepted(draft: RegistrationDraft) {
const next = { ...draft, accepted: true };
setContext(next);
writeRegistrationContext(next);
}
function startAgain() {
clearRegistrationContext();
setContext({ email: "", scenario: "", accepted: false });
}
return (
<Page
title="Регистрация"
lead="Создайте аккаунт и выберите, как вы будете пользоваться платформой."
>
{context.accepted ? (
<div>
<Section title="Запрос принят">
<p role="status" aria-live="polite">
Если для этого адреса требуется подтверждение, письмо будет отправлено. Выбранный
сценарий: {scenarioLabel(context.scenario)}.
</p>
<ResendVerificationForm initialEmail={context.email} />
<TextLink to={paths.login}>Перейти ко входу</TextLink>
<Button type="button" variant="quiet" onClick={startAgain}>
Начать другую регистрацию
</Button>
</Section>
</div>
) : (
<Section title="Данные аккаунта">
<RegisterForm
initialEmail={context.email}
initialScenario={context.scenario}
onDraftChange={saveDraft}
onAccepted={markAccepted}
/>
</Section>
)}
</Page>
);
}
@@ -0,0 +1,35 @@
import { useCallback, useState } from "react";
import { ConfirmEmailForm } from "../../../features/confirm-email";
import { ResendVerificationForm } from "../../../features/resend-email-verification";
import { Page, Section } from "../../../shared/ui";
import { clearRegistrationContext } from "../model/registration-context";
export function VerifyEmailPage() {
const [needsResend, setNeedsResend] = useState(false);
const requestResend = useCallback(() => setNeedsResend(true), []);
const linkReady = useCallback(() => setNeedsResend(false), []);
const finishConfirmation = useCallback(() => {
setNeedsResend(false);
clearRegistrationContext();
}, []);
return (
<Page
title="Подтверждение почты"
lead="Подтвердите адрес ссылкой из письма и паролем регистрации."
>
<Section title="Подтвердить адрес">
<ConfirmEmailForm
onResendNeeded={requestResend}
onTokenReady={linkReady}
onConfirmed={finishConfirmation}
/>
</Section>
{needsResend ? (
<Section title="Запросить новое письмо">
<ResendVerificationForm />
</Section>
) : null}
</Page>
);
}
@@ -0,0 +1 @@
export { CandidateOnboardingPage } from "./ui/candidate-onboarding-page";
@@ -0,0 +1,48 @@
import { Navigate } from "react-router-dom";
import { useGetCurrentSession } from "../../../shared/api/endpoints/identity/identity";
import { getOnboardingDestination } from "../../../entities/session";
import { paths } from "../../../shared/config";
import { LoadingState, Page, Section, StatusView } from "../../../shared/ui";
export function CandidateOnboardingPage() {
const session = useGetCurrentSession();
if (!session.data) return <LoadingState label="Загружаем сохраненный шаг..." />;
const { onboarding_step: step, scenario } = session.data.account;
if (scenario !== "candidate") {
return (
<StatusView
kind="forbidden"
title="Этот шаг недоступен для вашего сценария"
description="Откройте кабинет, связанный с выбранным сценарием."
/>
);
}
if (step !== "candidate_consents" && step !== "candidate_questionnaire") {
const destination = getOnboardingDestination(session.data.account);
if (destination === paths.candidate.onboarding) {
return (
<StatusView
kind="error"
title="Не удалось определить сохраненный шаг"
description="Обновите страницу или обратитесь в поддержку."
/>
);
}
return <Navigate to={destination} replace />;
}
const stepTitle = step === "candidate_consents" ? "Согласия" : "Анкета";
const description =
step === "candidate_consents"
? "Следующий сохраненный шаг - согласия кандидата. Согласие C1 уже было показано отдельно при регистрации."
: "Следующий сохраненный шаг - анкета кандидата. После ее сохранения сервер откроет следующий этап.";
return (
<Page title="Первые шаги" eyebrow="Кабинет кандидата">
<Section title={stepTitle} description={description}>
<p>Этот шаг сохранен в аккаунте и будет открыт после следующего входа.</p>
</Section>
</Page>
);
}