setting up firebase and firebase auth

This commit is contained in:
Arjun Patel
2022-01-12 18:36:29 -08:00
parent c9e0fbfe2d
commit a83e319c78
5 changed files with 2387 additions and 32 deletions
+37
View File
@@ -0,0 +1,37 @@
import { getAuth, onAuthStateChanged, User } from "firebase/auth";
import React, { useContext, useEffect, useState } from "react";
const AuthContext = React.createContext(null);
export function useAuth() {
return useContext(AuthContext)
}
export function AuthProvider({ children }) {
const [currUser, setCurrUser] = useState<null | User>(null);
function loginSignup() {
return
}
useEffect(() => {
const unsubscribe = getAuth().onAuthStateChanged(user => {
// will be null or the firebase logged in user
setCurrUser(user)
});
return unsubscribe
}, [])
const value = {
currUser
}
return (
<AuthContext.Provider value={value}>
{children}
</AuthContext.Provider>
)
}