react-query-firebase 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,30 @@
1
1
  /**
2
- * Custom hook to manage an ID token for the current user.
3
- * This hook provides an `idToken` value and a `refresh` function to manually refresh the token.
4
- *
5
- * @returns {Object} An object containing:
6
- * @returns {string} idToken - The current ID token for the user.
7
- * @returns {Function} refresh - A function to refresh the ID token.
2
+ * @inline
8
3
  */
9
- export declare const useIdToken: () => {
4
+ export type UseIdTokenResult = {
10
5
  idToken: string;
11
- refresh: () => Promise<void>;
6
+ refresh: () => Promise<string | undefined>;
12
7
  };
8
+ /**
9
+ * A hook to manage the ID token.
10
+ * It monitors changes to the ID token and provides the token itself along with a refresh method to update the token when needed.
11
+ *
12
+ * @group Hook
13
+ *
14
+ * @returns {UseIdTokenResult}
15
+ *
16
+ * @example
17
+ * ```jsx
18
+ * export const MyComponent = () => {
19
+ * const result = useIdToken();
20
+ * useEffect(() => {
21
+ * const timeout = setTimeout(() => {
22
+ * result.refresh();
23
+ * }, 5000);
24
+ * return () => clearTimeout();
25
+ * }, [])
26
+ * console.log(resilt.idToken);
27
+ * };
28
+ * ```
29
+ */
30
+ export declare const useIdToken: () => UseIdTokenResult;
@@ -3,12 +3,26 @@ import { useCurrentUser } from "./useCurrentUser";
3
3
  import { onIdTokenChanged } from "firebase/auth";
4
4
  import { useAuth } from "./useAuth";
5
5
  /**
6
- * Custom hook to manage an ID token for the current user.
7
- * This hook provides an `idToken` value and a `refresh` function to manually refresh the token.
6
+ * A hook to manage the ID token.
7
+ * It monitors changes to the ID token and provides the token itself along with a refresh method to update the token when needed.
8
8
  *
9
- * @returns {Object} An object containing:
10
- * @returns {string} idToken - The current ID token for the user.
11
- * @returns {Function} refresh - A function to refresh the ID token.
9
+ * @group Hook
10
+ *
11
+ * @returns {UseIdTokenResult}
12
+ *
13
+ * @example
14
+ * ```jsx
15
+ * export const MyComponent = () => {
16
+ * const result = useIdToken();
17
+ * useEffect(() => {
18
+ * const timeout = setTimeout(() => {
19
+ * result.refresh();
20
+ * }, 5000);
21
+ * return () => clearTimeout();
22
+ * }, [])
23
+ * console.log(resilt.idToken);
24
+ * };
25
+ * ```
12
26
  */
13
27
  export const useIdToken = () => {
14
28
  const auth = useAuth();
@@ -27,7 +41,7 @@ export const useIdToken = () => {
27
41
  return;
28
42
  }
29
43
  const idToken = await currentUser.getIdToken(true);
30
- setIdToken(idToken);
44
+ return idToken;
31
45
  }, [currentUser, idToken]);
32
46
  useEffect(() => {
33
47
  callback();
package/package.json CHANGED
@@ -60,5 +60,5 @@
60
60
  "docs:build": "vitepress build docs",
61
61
  "docs:preview": "vitepress preview docs"
62
62
  },
63
- "version": "1.3.2"
63
+ "version": "1.3.3"
64
64
  }
@@ -4,14 +4,36 @@ import { onIdTokenChanged } from "firebase/auth";
4
4
  import { useAuth } from "./useAuth";
5
5
 
6
6
  /**
7
- * Custom hook to manage an ID token for the current user.
8
- * This hook provides an `idToken` value and a `refresh` function to manually refresh the token.
7
+ * @inline
8
+ */
9
+ export type UseIdTokenResult = {
10
+ idToken: string;
11
+ refresh: () => Promise<string | undefined>;
12
+ };
13
+
14
+ /**
15
+ * A hook to manage the ID token.
16
+ * It monitors changes to the ID token and provides the token itself along with a refresh method to update the token when needed.
9
17
  *
10
- * @returns {Object} An object containing:
11
- * @returns {string} idToken - The current ID token for the user.
12
- * @returns {Function} refresh - A function to refresh the ID token.
18
+ * @group Hook
19
+ *
20
+ * @returns {UseIdTokenResult}
21
+ *
22
+ * @example
23
+ * ```jsx
24
+ * export const MyComponent = () => {
25
+ * const result = useIdToken();
26
+ * useEffect(() => {
27
+ * const timeout = setTimeout(() => {
28
+ * result.refresh();
29
+ * }, 5000);
30
+ * return () => clearTimeout();
31
+ * }, [])
32
+ * console.log(resilt.idToken);
33
+ * };
34
+ * ```
13
35
  */
14
- export const useIdToken = () => {
36
+ export const useIdToken = (): UseIdTokenResult => {
15
37
  const auth = useAuth();
16
38
 
17
39
  const currentUser = useCurrentUser();
@@ -33,7 +55,7 @@ export const useIdToken = () => {
33
55
  }
34
56
 
35
57
  const idToken = await currentUser.getIdToken(true);
36
- setIdToken(idToken);
58
+ return idToken;
37
59
  }, [currentUser, idToken]);
38
60
 
39
61
  useEffect(() => {