-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2689181
commit 12ab9ca
Showing
6 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
/test-results/ | ||
|
||
# modules | ||
/auth/ | ||
/firestore/ | ||
/storage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./useAuthState"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Auth, AuthError, onAuthStateChanged, User } from "firebase/auth"; | ||
import { useEffect, useMemo } from "react"; | ||
import { ValueHookResult } from "../common"; | ||
import { useLoadingValue } from "../util/useLoadingValue"; | ||
|
||
export type UseAuthStateResult = ValueHookResult<User | null, AuthError>; | ||
|
||
export function useAuthState(auth: Auth): UseAuthStateResult { | ||
const { error, loading, setError, setValue, value } = useLoadingValue<User | null, AuthError>(auth.currentUser); | ||
|
||
useEffect(() => { | ||
const unsubscribe = onAuthStateChanged(auth, setValue, (e) => setError(e as AuthError)); | ||
|
||
return () => { | ||
unsubscribe(); | ||
}; | ||
}, [auth]); | ||
|
||
return useMemo(() => [value, loading, error], [value, loading, error]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./auth"; | ||
export * from "./common"; | ||
export * from "./firestore"; | ||
export * from "./storage"; | ||
|