File size: 1,236 Bytes
2184b19
 
 
 
 
fe78c73
2184b19
 
 
 
 
 
 
 
fe78c73
2184b19
 
 
fe78c73
 
 
2184b19
fe78c73
 
2184b19
 
 
fe78c73
 
2184b19
 
 
fe78c73
2184b19
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
"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(() => {
    // Simulation mode: Auto-login as guest after 1 second
    const timer = setTimeout(() => {
      setUser({ email: "guest@defrag.local", uid: "guest-simulation-mode" });
      setLoading(false);
    }, 1000);
    return () => clearTimeout(timer);
  }, []);

  const signInWithGoogle = async () => {
    // Simulation: instant guest login
    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);