| "use client"; |
|
|
| import { createContext, useContext, useEffect, useState } from "react"; |
|
|
| interface AuthContextType { |
| user: { email: string; uid: string } | null; |
| loading: boolean; |
| signInWithGoogle: () => Promise<void>; |
| logout: () => Promise<void>; |
| } |
|
|
| const AuthContext = createContext<AuthContextType>({} as AuthContextType); |
|
|
| export function AuthProvider({ children }: { children: React.ReactNode }) { |
| const [user, setUser] = useState<{ email: string; uid: string } | null>(null); |
| const [loading, setLoading] = useState(true); |
|
|
| useEffect(() => { |
| |
| const timer = setTimeout(() => { |
| setUser({ email: "guest@defrag.local", uid: "guest-simulation-mode" }); |
| setLoading(false); |
| }, 1000); |
| return () => clearTimeout(timer); |
| }, []); |
|
|
| const signInWithGoogle = async () => { |
| |
| setUser({ email: "guest@defrag.local", uid: "guest-simulation-mode" }); |
| }; |
|
|
| const logout = async () => { |
| setUser(null); |
| }; |
|
|
| return ( |
| <AuthContext.Provider value={{ user, loading, signInWithGoogle, logout }}> |
| {children} |
| </AuthContext.Provider> |
| ); |
| } |
|
|
| export const useAuth = () => useContext(AuthContext); |