File size: 872 Bytes
cc276cc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
"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>
);
};
|