feat(app): identity screens and /app shell — auth store, login/signup/reset flows, dashboard, account
- state/authStore: session subscription (initialize + onAuthStateChange), profile + roles load, recovery flag, URL failure; services/localeSync: profiles.locale <-> localeStore - routes: /login, /signup, /forgot-password, /reset-password, /auth/callback; guards RequireAuth (next=) and RedirectIfSignedIn; /app (dashboard), /app/account behind the guard - shell: AppLayout (desktop sidebar, light top bar, mobile drawer), SidebarNav, UserBadge, SignOutButton - account: personal / professional / preferences / security sections, one save each, Zod validation with i18n keys - ui: Icon, FormField, Notice, ButtonLink (buttonClassName shared), PasswordField, OAuthButtons (config-driven) - Home header: Mon espace / Se connecter when Supabase is configured; local tool routes untouched - i18n: auth.*, shell.*, dashboard.*, account.*, home.space.* in fr + en
This commit is contained in:
1 parent
0f7292f9b3
commit
c517ea267b
46 files changed
+2798
-11
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import type { Locale } from '@/i18n/types'
|
||||
|
||||
function isLocale(value: string): value is Locale {
|
||||
return value === 'fr' || value === 'en'
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps the UI language and profiles.locale together:
|
||||
* - when an account loads, its locale wins over the device choice (once per sign-in);
|
||||
* - while signed in, switching the language is saved to the profile.
|
||||
* Returns the stop function.
|
||||
*/
|
||||
export function startLocaleSync(): () => void {
|
||||
let appliedForUser: string | null = null
|
||||
|
||||
const stopAuth = useAuthStore.subscribe((state, previous) => {
|
||||
if (!state.user) {
|
||||
appliedForUser = null
|
||||
return
|
||||
}
|
||||
const profile = state.profile
|
||||
if (!profile || profile === previous.profile) return
|
||||
if (appliedForUser === state.user.id) return
|
||||
appliedForUser = state.user.id
|
||||
if (isLocale(profile.locale)) {
|
||||
useLocaleStore.getState().setLocale(profile.locale)
|
||||
}
|
||||
})
|
||||
|
||||
const stopLocale = useLocaleStore.subscribe((state) => {
|
||||
const auth = useAuthStore.getState()
|
||||
if (auth.status !== 'signed_in' || !auth.profile) return
|
||||
if (auth.profile.locale === state.locale) return
|
||||
void auth.updateProfile({ locale: state.locale }).catch(() => undefined)
|
||||
})
|
||||
|
||||
return () => {
|
||||
stopAuth()
|
||||
stopLocale()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user