mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
firebase auth hook/context
This commit is contained in:
11
src/contexts/authContext.ts
Normal file
11
src/contexts/authContext.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import React from "react";
|
||||
|
||||
interface AuthContextInterface {
|
||||
authUser: firebase.User | null | undefined;
|
||||
}
|
||||
|
||||
const AuthContext = React.createContext<AuthContextInterface>({
|
||||
authUser: undefined
|
||||
});
|
||||
|
||||
export default AuthContext;
|
||||
18
src/hooks/useAuth.ts
Normal file
18
src/hooks/useAuth.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { auth } from "../firebase";
|
||||
|
||||
const useAuth = () => {
|
||||
const [authUser, setAuthUser] = useState<firebase.User | null | undefined>(
|
||||
undefined
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
auth.onAuthStateChanged(token => {
|
||||
setAuthUser(token);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return authUser;
|
||||
};
|
||||
|
||||
export default useAuth;
|
||||
Reference in New Issue
Block a user