1 | import * as React from 'react';
|
2 | import { ReactFireOptions, ObservableStatus } from './';
|
3 | import type { Auth, User, IdTokenResult } from 'firebase/auth';
|
4 | declare type Claims = IdTokenResult['claims'];
|
5 | export declare function preloadUser(authResolver: () => Promise<Auth>): Promise<User | null | undefined>;
|
6 | /**
|
7 | * Subscribe to Firebase auth state changes, including token refresh
|
8 | *
|
9 | * @param options
|
10 | */
|
11 | export declare function useUser<T = unknown>(options?: ReactFireOptions<T>): ObservableStatus<User | null>;
|
12 | export declare function useIdTokenResult(user: User, forceRefresh?: boolean, options?: ReactFireOptions<IdTokenResult>): ObservableStatus<IdTokenResult>;
|
13 | export interface AuthCheckProps {
|
14 | fallback: React.ReactNode;
|
15 | children: React.ReactNode;
|
16 | requiredClaims?: Object;
|
17 | }
|
18 | export interface ClaimsCheckProps {
|
19 | user: User;
|
20 | fallback: React.ReactNode;
|
21 | children: React.ReactNode;
|
22 | requiredClaims: {
|
23 | [key: string]: any;
|
24 | };
|
25 | }
|
26 | export interface ClaimCheckErrors {
|
27 | [key: string]: any[];
|
28 | }
|
29 | export declare type SigninCheckResult = {
|
30 | signedIn: false;
|
31 | hasRequiredClaims: false;
|
32 | errors: {};
|
33 | user: null;
|
34 | } | {
|
35 | signedIn: true;
|
36 | hasRequiredClaims: boolean;
|
37 | errors: ClaimCheckErrors;
|
38 | user: User;
|
39 | };
|
40 | export interface SignInCheckOptionsBasic extends ReactFireOptions<SigninCheckResult> {
|
41 | forceRefresh?: boolean;
|
42 | }
|
43 | export interface SignInCheckOptionsClaimsObject extends SignInCheckOptionsBasic {
|
44 | requiredClaims: Claims;
|
45 | }
|
46 | export interface ClaimsValidator {
|
47 | (claims: Claims): {
|
48 | hasRequiredClaims: boolean;
|
49 | errors: ClaimCheckErrors | {};
|
50 | };
|
51 | }
|
52 | export interface SignInCheckOptionsClaimsValidator extends SignInCheckOptionsBasic {
|
53 | validateCustomClaims: ClaimsValidator;
|
54 | }
|
55 | /**
|
56 | * Subscribe to the signed-in status of a user.
|
57 | *
|
58 | * ```ts
|
59 | * const { status, data:signInCheckResult } = useSigninCheck();
|
60 | *
|
61 | * if (status === 'loading') {
|
62 | * return <LoadingSpinner />}
|
63 | *
|
64 | *
|
65 | * if (signInCheckResult.signedIn === true) {
|
66 | * return <ProfilePage user={signInCheckResult.user}/>
|
67 | * } else {
|
68 | * return <SignInForm />
|
69 | * }
|
70 | * ```
|
71 | *
|
72 | * Optionally check [custom claims](https://firebase.google.com/docs/auth/admin/custom-claims) of a user as well.
|
73 | *
|
74 | * ```ts
|
75 | * // pass in an object describing the custom claims a user must have
|
76 | * const {status, data: signInCheckResult} = useSignInCheck({requiredClaims: {admin: true}});
|
77 | *
|
78 | * // pass in a custom claims validator function
|
79 | * const {status, data: signInCheckResult} = useSignInCheck({validateCustomClaims: (userClaims) => {
|
80 | * // custom validation logic...
|
81 | * }});
|
82 | *
|
83 | * // You can optionally force-refresh the token
|
84 | * const {status, data: signInCheckResult} = useSignInCheck({forceRefresh: true, requiredClaims: {admin: true}});
|
85 | * ```
|
86 | */
|
87 | export declare function useSigninCheck(options?: SignInCheckOptionsBasic | SignInCheckOptionsClaimsObject | SignInCheckOptionsClaimsValidator): ObservableStatus<SigninCheckResult>;
|
88 | /**
|
89 | * @deprecated Use `useSignInCheck` instead
|
90 | *
|
91 | * Conditionally render children based on [custom claims](https://firebase.google.com/docs/auth/admin/custom-claims).
|
92 | *
|
93 | * Meant for Concurrent mode only (`<FirebaseAppProvider suspense=true />`). [More detail](https://github.com/FirebaseExtended/reactfire/issues/325#issuecomment-827654376).
|
94 | */
|
95 | export declare function ClaimsCheck({ user, fallback, children, requiredClaims }: ClaimsCheckProps): JSX.Element;
|
96 | /**
|
97 | * @deprecated Use `useSignInCheck` instead
|
98 | *
|
99 | * Conditionally render children based on signed-in status and [custom claims](https://firebase.google.com/docs/auth/admin/custom-claims).
|
100 | *
|
101 | * Meant for Concurrent mode only (`<FirebaseAppProvider suspense=true />`). [More detail](https://github.com/FirebaseExtended/reactfire/issues/325#issuecomment-827654376).
|
102 | */
|
103 | export declare function AuthCheck({ fallback, children, requiredClaims }: AuthCheckProps): JSX.Element;
|
104 | export {};
|