-
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(messaging): add useMessagingToken (#9)
- Loading branch information
1 parent
ccf9926
commit 8bc1f4e
Showing
8 changed files
with
69 additions
and
3 deletions.
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 |
---|---|---|
|
@@ -7,4 +7,5 @@ | |
/auth/ | ||
/database/ | ||
/firestore/ | ||
/messaging/ | ||
/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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ CHANGELOG.md | |
/auth/ | ||
/database/ | ||
/firestore/ | ||
/messaging/ | ||
/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
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 "./useMessagingToken"; |
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,30 @@ | ||
import { Messaging, getToken, GetTokenOptions } from "firebase/messaging"; | ||
import { ValueHookResult } from "../common"; | ||
import { useOnce } from "../internal/useOnce"; | ||
|
||
export type UseMessagingTokenResult = ValueHookResult<string, Error>; | ||
|
||
/** | ||
* Options to configure how the token will be fetched | ||
*/ | ||
export interface UseMessagingTokenOptions { | ||
getTokenOptions?: GetTokenOptions; | ||
} | ||
|
||
/** | ||
* Returns the messaging token. The token never updates. | ||
* | ||
* @param {Messaging} messaging Firebase Messaging instance | ||
* @param {UseMessagingTokenOptions} options Options to configure how the token will be fetched | ||
* @returns {UseMessagingTokenResult} Token, loading state, and error | ||
* * value: Messaging 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 useMessagingToken(messaging: Messaging, options?: UseMessagingTokenOptions): UseMessagingTokenResult { | ||
return useOnce( | ||
messaging, | ||
(m) => getToken(m, options?.getTokenOptions), | ||
() => true | ||
); | ||
} |