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

+2
View File
@@ -0,0 +1,2 @@
export { getOnboardingDestination } from "./model/onboarding-destination";
export { SessionGate } from "./ui/session-gate";
@@ -0,0 +1,26 @@
import { describe, expect, it } from "vitest";
import type { Account } from "../../../shared/api/schemas";
import { paths } from "../../../shared/config";
import { getOnboardingDestination } from "./onboarding-destination";
function account(
scenario: Account["scenario"],
onboarding_step: Account["onboarding_step"],
): Pick<Account, "scenario" | "onboarding_step"> {
return { scenario, onboarding_step };
}
describe("getOnboardingDestination", () => {
it.each([
["candidate", "candidate_consents", paths.candidate.onboarding],
["candidate", "candidate_profile", paths.candidate.profile],
["candidate", "candidate_questionnaire", paths.candidate.onboarding],
["candidate", "candidate_assessment", paths.candidate.assessment],
["candidate", "completed", paths.candidate.root],
["employer", "employer_company", paths.employer.company],
["employer", "completed", paths.employer.root],
["candidate", "employer_company", paths.candidate.onboarding],
] as const)("routes %s at %s to the saved step", (scenario, step, expected) => {
expect(getOnboardingDestination(account(scenario, step))).toBe(expected);
});
});
@@ -0,0 +1,25 @@
import type { Account } from "../../../shared/api/schemas";
import { paths } from "../../../shared/config";
/** Resolve the next page from the server-owned onboarding state. */
export function getOnboardingDestination(
account: Pick<Account, "scenario" | "onboarding_step">,
): string {
if (account.scenario === "employer") {
return account.onboarding_step === "completed" ? paths.employer.root : paths.employer.company;
}
switch (account.onboarding_step) {
case "candidate_consents":
case "candidate_questionnaire":
return paths.candidate.onboarding;
case "candidate_profile":
return paths.candidate.profile;
case "candidate_assessment":
return paths.candidate.assessment;
case "employer_company":
return paths.candidate.onboarding;
case "completed":
return paths.candidate.root;
}
}
@@ -0,0 +1,57 @@
import { ApiRequestError } from "../../../shared/api";
import { useGetCurrentSession } from "../../../shared/api/endpoints/identity/identity";
import type { Account } from "../../../shared/api/schemas";
import { paths } from "../../../shared/config";
import { ButtonLink, ErrorState, ForbiddenState, LoadingState } from "../../../shared/ui";
import { Navigate, Outlet } from "react-router-dom";
type SessionGateProps = {
scenario: Account["scenario"];
};
/** Restores the HttpOnly-cookie session and keeps its CSRF token in query memory. */
export function SessionGate({ scenario }: SessionGateProps) {
const session = useGetCurrentSession();
if (session.isPending) {
return <LoadingState label="Проверяем вход..." />;
}
if (session.isError) {
if (session.error instanceof ApiRequestError && session.error.status === 401) {
return <Navigate to={paths.login} replace />;
}
if (session.error instanceof ApiRequestError && session.error.status === 403) {
return (
<ForbiddenState
error={session.error}
title="Не удалось проверить вход"
description="Обновите страницу и войдите снова."
action={<ButtonLink to={paths.login}>Перейти ко входу</ButtonLink>}
/>
);
}
return (
<ErrorState
error={session.error}
isRetrying={session.isRefetching}
onRetry={() => void session.refetch()}
title="Не удалось проверить вход"
/>
);
}
if (session.data.account.scenario !== scenario) {
return (
<ForbiddenState
title="Этот раздел недоступен для вашего сценария"
description="Войдите в кабинет, связанный с выбранным при регистрации сценарием."
action={<ButtonLink to={paths.login}>Перейти ко входу</ButtonLink>}
/>
);
}
return <Outlet />;
}