feat(auth): useAuth + ProtectedRoute + signUp dans auth-client (Sprint 1 étape 2)

This commit is contained in:
Hermann_Kitio 2026-04-18 02:09:46 +03:00
parent 107a37d197
commit 38777796aa
19 changed files with 2620 additions and 191 deletions

View file

@ -1,4 +1,4 @@
import { createClient } from '@supabase/supabase-js'
import { createClient, type Session, type User } from '@supabase/supabase-js'
import { env } from '@/shared/config/env'
import { logger } from './logger'
@ -17,6 +17,32 @@ export async function signIn(email: string, password: string) {
return supabase.auth.signInWithPassword({ email, password })
}
export async function signUp(email: string, password: string) {
return supabase.auth.signUp({ email, password })
}
export async function signOut() {
return supabase.auth.signOut()
}
export async function getCurrentSession(): Promise<Session | null> {
const { data, error } = await supabase.auth.getSession()
if (error) {
logger.error('Auth session fetch failed', { name: error.name })
return null
}
return data.session
}
/**
* S'abonne aux changements d'état d'authentification Supabase.
* Retourne une fonction de désabonnement à appeler au cleanup.
*/
export function subscribeToAuthChanges(callback: (session: Session | null) => void): () => void {
const { data } = supabase.auth.onAuthStateChange((_event, session) => {
callback(session)
})
return () => data.subscription.unsubscribe()
}
export type { Session, User }