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,13 @@
|
||||
import { Navigate } from "react-router-dom";
|
||||
import { getOnboardingDestination } from "../../entities/session";
|
||||
import { PlaceholderPage } from "../../pages/placeholder";
|
||||
import { useGetCurrentSession } from "../../shared/api/endpoints/identity/identity";
|
||||
|
||||
export function CandidateHomeRoute() {
|
||||
const session = useGetCurrentSession();
|
||||
if (!session.data) return <PlaceholderPage screen="candidateHome" />;
|
||||
if (session.data.account.onboarding_step !== "completed") {
|
||||
return <Navigate to={getOnboardingDestination(session.data.account)} replace />;
|
||||
}
|
||||
return <PlaceholderPage screen="candidateHome" />;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { QueryClientProvider } from "@tanstack/react-query";
|
||||
import { renderToString } from "react-dom/server";
|
||||
import { StaticRouterProvider, createStaticHandler, createStaticRouter } from "react-router-dom";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getGetCurrentSessionQueryKey } from "../../shared/api/endpoints/identity/identity";
|
||||
import { createQueryClient } from "../providers/query-client";
|
||||
import { routes } from "./routes";
|
||||
|
||||
@@ -15,8 +16,32 @@ async function render(path: string): Promise<string | Response> {
|
||||
return context;
|
||||
}
|
||||
const router = createStaticRouter(handler.dataRoutes, context);
|
||||
const queryClient = createQueryClient();
|
||||
const scenario = path.startsWith("/employer") ? "employer" : "candidate";
|
||||
if (path.startsWith("/candidate") || path.startsWith("/employer")) {
|
||||
queryClient.setQueryData(getGetCurrentSessionQueryKey(), {
|
||||
account: {
|
||||
id: "11111111-1111-4111-8111-111111111111",
|
||||
email: "person@example.test",
|
||||
email_verified: true,
|
||||
scenario,
|
||||
onboarding_step:
|
||||
path === "/candidate/onboarding"
|
||||
? "candidate_consents"
|
||||
: path === "/candidate/profile"
|
||||
? "candidate_profile"
|
||||
: path === "/candidate/assessment"
|
||||
? "candidate_assessment"
|
||||
: scenario === "candidate"
|
||||
? "completed"
|
||||
: "employer_company",
|
||||
created_at: "2026-10-07T12:00:00Z",
|
||||
},
|
||||
csrf_token: "A".repeat(43),
|
||||
});
|
||||
}
|
||||
return renderToString(
|
||||
<QueryClientProvider client={createQueryClient()}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<StaticRouterProvider router={router} context={context} hydrate={false} />
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { redirect, type RouteObject } from "react-router-dom";
|
||||
import { LoginPage, RegisterPage, VerifyEmailPage } from "../../pages/auth";
|
||||
import { CandidateOnboardingPage } from "../../pages/candidate-onboarding";
|
||||
import { SessionGate } from "../../entities/session";
|
||||
import { NotFoundPage } from "../../pages/not-found";
|
||||
import { PlaceholderPage } from "../../pages/placeholder";
|
||||
import { StatusPage } from "../../pages/status";
|
||||
@@ -9,11 +12,11 @@ import { EmployerShell } from "../../widgets/employer-shell";
|
||||
import { PublicShell } from "../../widgets/public-shell";
|
||||
import { RootLayout } from "../ui/root-layout";
|
||||
import { RouteErrorPage } from "../ui/route-error-page";
|
||||
import { CandidateHomeRoute } from "./candidate-home-route";
|
||||
|
||||
/**
|
||||
* Route tree with three groups: public pages, the candidate cabinet, and the
|
||||
* employer cabinet. Each group has its own shell and its own not-found page.
|
||||
* Access control is not implemented yet; the server will enforce it.
|
||||
* Route tree with public pages and role-specific cabinets. Protected shells
|
||||
* restore the server session before they render any cabinet child.
|
||||
*/
|
||||
export const routes: RouteObject[] = [
|
||||
{
|
||||
@@ -24,9 +27,9 @@ export const routes: RouteObject[] = [
|
||||
element: <PublicShell />,
|
||||
children: [
|
||||
{ index: true, element: <WelcomePage /> },
|
||||
{ path: paths.login, element: <PlaceholderPage screen="login" /> },
|
||||
{ path: paths.register, element: <PlaceholderPage screen="register" /> },
|
||||
{ path: paths.verifyEmail, element: <PlaceholderPage screen="verifyEmail" /> },
|
||||
{ path: paths.login, element: <LoginPage /> },
|
||||
{ path: paths.register, element: <RegisterPage /> },
|
||||
{ path: paths.verifyEmail, element: <VerifyEmailPage /> },
|
||||
{ path: paths.support, element: <PlaceholderPage screen="support" /> },
|
||||
{ path: paths.status, element: <StatusPage /> },
|
||||
{ path: "*", element: <NotFoundPage /> },
|
||||
@@ -36,27 +39,38 @@ export const routes: RouteObject[] = [
|
||||
path: paths.candidate.root,
|
||||
element: <CandidateShell />,
|
||||
children: [
|
||||
{ index: true, element: <PlaceholderPage screen="candidateHome" /> },
|
||||
{
|
||||
path: paths.candidate.onboarding,
|
||||
element: <PlaceholderPage screen="candidateOnboarding" />,
|
||||
},
|
||||
{ path: paths.candidate.profile, element: <PlaceholderPage screen="candidateProfile" /> },
|
||||
{
|
||||
path: paths.candidate.assessment,
|
||||
element: <PlaceholderPage screen="candidateAssessment" />,
|
||||
},
|
||||
{ path: paths.candidate.results, element: <PlaceholderPage screen="candidateResults" /> },
|
||||
{
|
||||
path: paths.candidate.invitations,
|
||||
element: <PlaceholderPage screen="candidateInvitations" />,
|
||||
},
|
||||
{ path: paths.candidate.privacy, element: <PlaceholderPage screen="candidatePrivacy" /> },
|
||||
{
|
||||
path: "*",
|
||||
element: (
|
||||
<NotFoundPage homePath={paths.candidate.root} homeLabel="В кабинет кандидата" />
|
||||
),
|
||||
element: <SessionGate scenario="candidate" />,
|
||||
children: [
|
||||
{ index: true, element: <CandidateHomeRoute /> },
|
||||
{ path: paths.candidate.onboarding, element: <CandidateOnboardingPage /> },
|
||||
{
|
||||
path: paths.candidate.profile,
|
||||
element: <PlaceholderPage screen="candidateProfile" />,
|
||||
},
|
||||
{
|
||||
path: paths.candidate.assessment,
|
||||
element: <PlaceholderPage screen="candidateAssessment" />,
|
||||
},
|
||||
{
|
||||
path: paths.candidate.results,
|
||||
element: <PlaceholderPage screen="candidateResults" />,
|
||||
},
|
||||
{
|
||||
path: paths.candidate.invitations,
|
||||
element: <PlaceholderPage screen="candidateInvitations" />,
|
||||
},
|
||||
{
|
||||
path: paths.candidate.privacy,
|
||||
element: <PlaceholderPage screen="candidatePrivacy" />,
|
||||
},
|
||||
{
|
||||
path: "*",
|
||||
element: (
|
||||
<NotFoundPage homePath={paths.candidate.root} homeLabel="В кабинет кандидата" />
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -64,23 +78,33 @@ export const routes: RouteObject[] = [
|
||||
path: paths.employer.root,
|
||||
element: <EmployerShell />,
|
||||
children: [
|
||||
// The employer flow starts with the company profile.
|
||||
{ index: true, loader: () => redirect(paths.employer.company) },
|
||||
{ path: paths.employer.company, element: <PlaceholderPage screen="employerCompany" /> },
|
||||
{ path: paths.employer.needs, element: <PlaceholderPage screen="employerNeeds" /> },
|
||||
{
|
||||
path: paths.employer.candidates,
|
||||
element: <PlaceholderPage screen="employerCandidates" />,
|
||||
},
|
||||
{
|
||||
path: paths.employer.invitations,
|
||||
element: <PlaceholderPage screen="employerInvitations" />,
|
||||
},
|
||||
{
|
||||
path: "*",
|
||||
element: (
|
||||
<NotFoundPage homePath={paths.employer.company} homeLabel="В кабинет работодателя" />
|
||||
),
|
||||
element: <SessionGate scenario="employer" />,
|
||||
children: [
|
||||
{ index: true, loader: () => redirect(paths.employer.company) },
|
||||
{
|
||||
path: paths.employer.company,
|
||||
element: <PlaceholderPage screen="employerCompany" />,
|
||||
},
|
||||
{ path: paths.employer.needs, element: <PlaceholderPage screen="employerNeeds" /> },
|
||||
{
|
||||
path: paths.employer.candidates,
|
||||
element: <PlaceholderPage screen="employerCandidates" />,
|
||||
},
|
||||
{
|
||||
path: paths.employer.invitations,
|
||||
element: <PlaceholderPage screen="employerInvitations" />,
|
||||
},
|
||||
{
|
||||
path: "*",
|
||||
element: (
|
||||
<NotFoundPage
|
||||
homePath={paths.employer.company}
|
||||
homeLabel="В кабинет работодателя"
|
||||
/>
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user