cjo93 commited on
Commit
fe78c73
·
verified ·
1 Parent(s): f13b3dc

Update src/lib/auth-context.tsx

Browse files
Files changed (1) hide show
  1. src/lib/auth-context.tsx +10 -27
src/lib/auth-context.tsx CHANGED
@@ -1,23 +1,9 @@
1
  "use client";
2
 
3
  import { createContext, useContext, useEffect, useState } from "react";
4
- import { initializeApp, getApps } from "firebase/app";
5
- import { getAuth, onAuthStateChanged, User, GoogleAuthProvider, signInWithPopup, signOut as firebaseSignOut } from "firebase/auth";
6
-
7
- const firebaseConfig = {
8
- apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
9
- authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
10
- projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
11
- storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
12
- messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
13
- appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
14
- };
15
-
16
- const app = getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0];
17
- const auth = getAuth(app);
18
 
19
  interface AuthContextType {
20
- user: User | null;
21
  loading: boolean;
22
  signInWithGoogle: () => Promise<void>;
23
  logout: () => Promise<void>;
@@ -26,28 +12,25 @@ interface AuthContextType {
26
  const AuthContext = createContext<AuthContextType>({} as AuthContextType);
27
 
28
  export function AuthProvider({ children }: { children: React.ReactNode }) {
29
- const [user, setUser] = useState<User | null>(null);
30
  const [loading, setLoading] = useState(true);
31
 
32
  useEffect(() => {
33
- const unsubscribe = onAuthStateChanged(auth, (currentUser) => {
34
- setUser(currentUser);
 
35
  setLoading(false);
36
- });
37
- return () => unsubscribe();
38
  }, []);
39
 
40
  const signInWithGoogle = async () => {
41
- try {
42
- const provider = new GoogleAuthProvider();
43
- await signInWithPopup(auth, provider);
44
- } catch (error) {
45
- console.error("Auth Error:", error);
46
- }
47
  };
48
 
49
  const logout = async () => {
50
- await firebaseSignOut(auth);
51
  };
52
 
53
  return (
 
1
  "use client";
2
 
3
  import { createContext, useContext, useEffect, useState } from "react";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  interface AuthContextType {
6
+ user: { email: string; uid: string } | null;
7
  loading: boolean;
8
  signInWithGoogle: () => Promise<void>;
9
  logout: () => Promise<void>;
 
12
  const AuthContext = createContext<AuthContextType>({} as AuthContextType);
13
 
14
  export function AuthProvider({ children }: { children: React.ReactNode }) {
15
+ const [user, setUser] = useState<{ email: string; uid: string } | null>(null);
16
  const [loading, setLoading] = useState(true);
17
 
18
  useEffect(() => {
19
+ // Simulation mode: Auto-login as guest after 1 second
20
+ const timer = setTimeout(() => {
21
+ setUser({ email: "guest@defrag.local", uid: "guest-simulation-mode" });
22
  setLoading(false);
23
+ }, 1000);
24
+ return () => clearTimeout(timer);
25
  }, []);
26
 
27
  const signInWithGoogle = async () => {
28
+ // Simulation: instant guest login
29
+ setUser({ email: "guest@defrag.local", uid: "guest-simulation-mode" });
 
 
 
 
30
  };
31
 
32
  const logout = async () => {
33
+ setUser(null);
34
  };
35
 
36
  return (