feat: add profile check mutation and enhance navigation access control

This commit is contained in:
estifanos
2026-08-01 08:23:37 +00:00
parent cdb5812124
commit 6fce0b4fa7
2 changed files with 48 additions and 2 deletions

View File

@@ -27,8 +27,10 @@ import { notify, useErrorHandler } from "@ema-platform/ui";
import {
authStorage,
setUser,
setCurrentProfile,
logout,
type AuthUser,
type CurrentProfile,
} from "@ema-platform/auth";
import { useAppDispatch, useAppSelector } from "../../../store/hooks";
import {
@@ -144,6 +146,10 @@ export function ProfileSetupPage() {
const [profileTrigger] = useApiMutation<{ id: string }>();
const [addressTrigger] = useApiMutation<{ id: string }>();
const [meTrigger] = useApiMutation<AuthUser>();
const [profileCheckTrigger] = useApiMutation<{
total: number;
items: CurrentProfile[];
}>();
const [fetchProfessions] = useApiMutation<{
count: number;
items: Array<{ id: string; name: { en: string } }>;
@@ -300,6 +306,21 @@ export function ProfileSetupPage() {
const me = await meTrigger({ url: "/auth/me", method: "GET" }).unwrap();
dispatch(setUser(me));
// POST /profiles doesn't return the profession relation the portal's nav/route
// guard reads (PortalLayout.tsx) — re-fetch with it, same as LoginPage does on login.
try {
const q = `w=user_id:=:${me.id}&i=user,address,profession`;
const profileCheck = await profileCheckTrigger({
url: `/profiles?q=${encodeURIComponent(q)}`,
method: "GET",
}).unwrap();
if (profileCheck.total > 0 && profileCheck.items.length > 0) {
dispatch(setCurrentProfile(profileCheck.items[0]));
}
} catch {
// non-fatal — sidebar/route guard falls back to FALLBACK_ACCESS
}
notify.success("Profile setup complete!");
navigate("/dashboard");
} catch (e) {