the-tip-top-frontend/hooks/useAuth.ts
2025-11-17 23:38:02 +01:00

18 lines
505 B
TypeScript

import { useContext } from 'react';
import { AuthContext } from '@/contexts/AuthContext';
/**
* Hook personnalisé pour accéder au contexte d'authentification
* @returns Contexte d'authentification avec user, login, register, logout, etc.
* @throws Error si utilisé en dehors du AuthProvider
*/
export function useAuth() {
const context = useContext(AuthContext);
if (!context) {
throw new Error('useAuth doit être utilisé à l\'intérieur d\'un AuthProvider');
}
return context;
}