- 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
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { useAuthStore } from '@/state/authStore'
|
|
|
|
/** Two-letter monogram from the display name, else the email. */
|
|
export function monogram(name: string | undefined, email: string | undefined) {
|
|
const source = (name ?? '').trim() || (email ?? '').trim()
|
|
if (!source) return '?'
|
|
const parts = source.split(/\s+/).filter(Boolean)
|
|
const letters =
|
|
parts.length >= 2 ? parts[0][0] + parts[1][0] : source.slice(0, 2)
|
|
return letters.toUpperCase()
|
|
}
|
|
|
|
/** Avatar monogram + display name + email, as shown at the bottom of the sidebar. */
|
|
export default function UserBadge() {
|
|
const profile = useAuthStore((s) => s.profile)
|
|
const user = useAuthStore((s) => s.user)
|
|
const name = profile?.display_name ?? user?.email ?? ''
|
|
return (
|
|
<div className="flex items-center gap-3 min-w-0">
|
|
<span
|
|
aria-hidden="true"
|
|
className="grid h-9 w-9 shrink-0 place-items-center rounded-full bg-[var(--color-accent)] text-sm font-semibold text-white"
|
|
>
|
|
{monogram(profile?.display_name, user?.email)}
|
|
</span>
|
|
<span className="flex min-w-0 flex-col leading-tight">
|
|
<span className="truncate text-sm font-medium text-[var(--color-ink)]">
|
|
{name}
|
|
</span>
|
|
{user?.email && profile?.display_name && (
|
|
<span className="truncate text-xs text-[var(--color-ink-muted)]">
|
|
{user.email}
|
|
</span>
|
|
)}
|
|
</span>
|
|
</div>
|
|
)
|
|
}
|