| "use client"; | |
| import React, { createContext, useContext } from 'react'; | |
| import { useAuthCore } from '@/hooks/use-auth'; | |
| import { LoadingScreen } from '@/components/loading-screen'; | |
| type AuthContextValue = ReturnType<typeof useAuthCore>; | |
| const AuthContext = createContext<AuthContextValue | null>(null); | |
| export const useAuth = () => { | |
| const context = useContext(AuthContext); | |
| if (!context) { | |
| throw new Error('useAuth must be used within an AuthProvider'); | |
| } | |
| return context; | |
| }; | |
| export const AuthProvider = ({ children }: { children: React.ReactNode }) => { | |
| const authData = useAuthCore(); | |
| return ( | |
| <AuthContext.Provider value={authData}> | |
| {authData.authStatus === 'loading' ? ( | |
| <LoadingScreen /> | |
| ) : ( | |
| children | |
| )} | |
| </AuthContext.Provider> | |
| ); | |
| }; | |