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,17 @@
|
||||
/** Absolute URLs the auth emails and OAuth providers come back to. */
|
||||
export const AUTH_CALLBACK_PATH = '/auth/callback'
|
||||
export const RESET_PASSWORD_PATH = '/reset-password'
|
||||
export const APP_HOME_PATH = '/app'
|
||||
|
||||
export function absoluteUrl(path: string): string {
|
||||
return new URL(path, window.location.origin).toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* The `next` query value is only honoured when it is a same-origin path:
|
||||
* never a scheme, never a protocol-relative URL.
|
||||
*/
|
||||
export function safeNextPath(raw: string | null, fallback = APP_HOME_PATH) {
|
||||
if (!raw || !raw.startsWith('/') || raw.startsWith('//')) return fallback
|
||||
return raw
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { AuthFailure, ProfileError } from '@faunosteo/supabase'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
/** One sentence per failure kind; anything else is the generic line. */
|
||||
export function useAuthFailureMessage(): (error: unknown) => string {
|
||||
const t = useT()
|
||||
return (error) => {
|
||||
if (error instanceof AuthFailure) return t(`auth.failure.${error.kind}`)
|
||||
if (error instanceof ProfileError) return t('account.error.save_failed')
|
||||
return t('auth.failure.unknown')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
/**
|
||||
* Mirrors supabase/config.toml: minimum_password_length = 12,
|
||||
* password_requirements = "lower_upper_letters_digits". Issue messages are
|
||||
* i18n keys; the forms translate them next to the field.
|
||||
*/
|
||||
export const PASSWORD_MIN_LENGTH = 12
|
||||
|
||||
export const emailSchema = z
|
||||
.string()
|
||||
.trim()
|
||||
.min(1, 'auth.error.email_required')
|
||||
.email('auth.error.email_invalid')
|
||||
|
||||
export const passwordSchema = z
|
||||
.string()
|
||||
.min(PASSWORD_MIN_LENGTH, 'auth.error.password_rules')
|
||||
.regex(/[a-z]/, 'auth.error.password_rules')
|
||||
.regex(/[A-Z]/, 'auth.error.password_rules')
|
||||
.regex(/[0-9]/, 'auth.error.password_rules')
|
||||
|
||||
export const displayNameSchema = z
|
||||
.string()
|
||||
.trim()
|
||||
.min(1, 'auth.error.display_name_required')
|
||||
.max(80, 'auth.error.display_name_too_long')
|
||||
|
||||
export const loginSchema = z.object({
|
||||
email: emailSchema,
|
||||
password: z.string().min(1, 'auth.error.password_required'),
|
||||
})
|
||||
|
||||
export const signupSchema = z
|
||||
.object({
|
||||
displayName: displayNameSchema,
|
||||
email: emailSchema,
|
||||
password: passwordSchema,
|
||||
passwordConfirm: z.string(),
|
||||
})
|
||||
.refine((v) => v.password === v.passwordConfirm, {
|
||||
message: 'auth.error.password_mismatch',
|
||||
path: ['passwordConfirm'],
|
||||
})
|
||||
|
||||
export const newPasswordSchema = z
|
||||
.object({ password: passwordSchema, passwordConfirm: z.string() })
|
||||
.refine((v) => v.password === v.passwordConfirm, {
|
||||
message: 'auth.error.password_mismatch',
|
||||
path: ['passwordConfirm'],
|
||||
})
|
||||
|
||||
export type FieldErrors<T> = Partial<Record<keyof T & string, string>>
|
||||
|
||||
/** First issue per field, as an i18n key. */
|
||||
export function fieldErrors<T>(error: z.ZodError<T>): FieldErrors<T> {
|
||||
const out: Record<string, string> = {}
|
||||
for (const issue of error.issues) {
|
||||
const field = String(issue.path[0] ?? '')
|
||||
if (field && !out[field]) out[field] = issue.message
|
||||
}
|
||||
return out as FieldErrors<T>
|
||||
}
|
||||
Reference in new issue
Block a user