MCPcopy Create free account
hub / github.com/Bitbox-Connect/Bitbox / AuthProvider

Function AuthProvider

client/src/contexts/authContext/index.jsx:12–64  ·  view source on GitHub ↗
({ children })

Source from the content-addressed store, hash-verified

10}
11
12export function AuthProvider({ children }) {
13 const [currentUser, setCurrentUser] = useState(null);
14 const [userLoggedIn, setUserLoggedIn] = useState(false);
15 const [isEmailUser, setIsEmailUser] = useState(false);
16 const [isGoogleUser, setIsGoogleUser] = useState(false);
17 const [loading, setLoading] = useState(true);
18
19 useEffect(() => {
20 const unsubscribe = onAuthStateChanged(auth, initializeUser);
21 return unsubscribe;
22 }, []);
23
24 async function initializeUser(user) {
25 if (user) {
26
27 setCurrentUser({ ...user });
28
29 // check if provider is email and password login
30 const isEmail = user.providerData.some(
31 (provider) => provider.providerId === "password"
32 );
33 setIsEmailUser(isEmail);
34
35 // check if the auth provider is google or not
36 // const isGoogle = user.providerData.some(
37 // (provider) => provider.providerId === GoogleAuthProvider.PROVIDER_ID
38 // );
39 // setIsGoogleUser(isGoogle);
40
41 setUserLoggedIn(true);
42 } else {
43 setCurrentUser(null);
44 setUserLoggedIn(false);
45 }
46
47 setLoading(false);
48 }
49
50 const value = {
51 userLoggedIn,
52 isEmailUser,
53 isGoogleUser,
54 currentUser,
55 setCurrentUser,
56 setUserLoggedIn
57 };
58
59 return (
60 <AuthContext.Provider value={value}>
61 {!loading && children}
62 </AuthContext.Provider>
63 );
64}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected