-
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.
feat(app-check): add useAppCheckToken (#158)
- Loading branch information
1 parent
654340a
commit 81d95c2
Showing
6 changed files
with
55 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
/test-results/ | ||
|
||
# modules | ||
/app-check/ | ||
/auth/ | ||
/database/ | ||
/firestore/ | ||
|
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 "./useAppCheckToken.js"; |
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,25 @@ | ||
import { AppCheck, AppCheckTokenResult, onTokenChanged } from "firebase/app-check"; | ||
import { useCallback } from "react"; | ||
import { ValueHookResult } from "../common/index.js"; | ||
import { useListen, UseListenOnChange } from "../internal/useListen.js"; | ||
import { LoadingState } from "../internal/useLoadingValue.js"; | ||
|
||
export type UseAppCheckToken = ValueHookResult<AppCheckTokenResult | null, Error>; | ||
|
||
/** | ||
* Returns and updates the current App Check token | ||
* | ||
* @param {AppCheck} appCheck Firebase App Check instance | ||
* @returns {UseAppCheckToken} App Check token, loading state, and error | ||
* * value: App Check token; `undefined` if token is currently being fetched, or an error occurred | ||
* * loading: `true` while fetching the token; `false` if the token was fetched successfully or an error occurred | ||
* * error: `undefined` if no error occurred | ||
*/ | ||
export function useAppCheckToken(appCheck: AppCheck): UseAppCheckToken { | ||
const onChange: UseListenOnChange<AppCheckTokenResult | null, Error, AppCheck> = useCallback( | ||
(stableAppCheck, next, error) => onTokenChanged(stableAppCheck, next, error), | ||
[] | ||
); | ||
|
||
return useListen(appCheck, onChange, () => true, LoadingState); | ||
} |
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