mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
refactor: simplify profile lookup and navigation logic commit
This commit is contained in:
@@ -46,7 +46,7 @@ export function LoginPage() {
|
||||
const [rememberMe, setRememberMe] = useState(true);
|
||||
const [loginTrigger] = useApiMutation<LoginPayload>();
|
||||
const [meTrigger] = useApiMutation<AuthUser>();
|
||||
const [profileCheckTrigger] = useApiMutation<{ total: number; items: Array<{ id: string; user: { id: string }; isComplete: boolean }> }>();
|
||||
const [profileCheckTrigger] = useApiMutation<{ id: string }>();
|
||||
|
||||
const {
|
||||
register,
|
||||
@@ -72,31 +72,35 @@ export function LoginPage() {
|
||||
}).unwrap();
|
||||
dispatch(setUser(me));
|
||||
|
||||
let hasProfile = false;
|
||||
try {
|
||||
const profiles = await profileCheckTrigger({
|
||||
url: `/profiles?q=${encodeURIComponent('i=user')}`,
|
||||
const profile = await profileCheckTrigger({
|
||||
url: `/profiles/by-user/${me.id}`,
|
||||
method: 'GET',
|
||||
}).unwrap();
|
||||
const userProfile = profiles.items?.find((p) => p.user?.id === me.id);
|
||||
|
||||
if (userProfile?.isComplete) {
|
||||
authStorage.setProfileId(userProfile.id);
|
||||
} else {
|
||||
navigate('/profile-setup');
|
||||
return;
|
||||
}
|
||||
authStorage.setProfileId(profile.id);
|
||||
hasProfile = true;
|
||||
} catch {
|
||||
// profile not found — redirect to setup
|
||||
}
|
||||
|
||||
if (!me.isPhoneNumberVerified) {
|
||||
navigate('/otp-verify', {
|
||||
state: {
|
||||
email: me.email,
|
||||
phoneNumber: me.phoneNumber,
|
||||
needsProfile: !hasProfile,
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasProfile) {
|
||||
navigate('/profile-setup');
|
||||
return;
|
||||
}
|
||||
|
||||
if (me.isPhoneNumberVerified) {
|
||||
navigate(loginRedirectPath);
|
||||
} else {
|
||||
navigate('/otp-verify', {
|
||||
state: { email: me.email, phoneNumber: me.phoneNumber },
|
||||
});
|
||||
}
|
||||
navigate(loginRedirectPath);
|
||||
} catch {
|
||||
notify.error('Invalid email or password');
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user