mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-09-08 01:55:42 +00:00
feat: add profile check mutation and enhance navigation access control
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user