-
Notifications
You must be signed in to change notification settings - Fork 407
Open
Description
Version info
React:
18.2.0
Next:
13.2.4
Firebase:
9.22.1
ReactFire:
4.2.3
Steps to reproduce
I initialize reactfire using the code below. As you can see, I have a guard checking if the user is signed in. And only if the user is signed in the children/pages are rendered.
function AuthWrapper(props: any) {
const app = useFirebaseApp();
const auth = getAuth(app);
return <AuthProvider sdk={auth}>{props.children}</AuthProvider>;
}
function AuthGuard(props: React.PropsWithChildren<{ fallback: JSX.Element }>) {
const router = useRouter();
const { status, data: signInCheckResult } = useSigninCheck();
const { data: user } = useUser();
if (status === "loading") {
return props.fallback;
}
if (signInCheckResult?.signedIn === true) {
return props.children as JSX.Element;
} else {
return router.push("/login");
}
}
export default function App({
Component,
pageProps
}: MyAppProps) {
return (
<FirebaseAppProvider firebaseConfig={firebaseConfig}>
<AuthWrapper>
<AuthGuard fallback={<PageLoader />}>
<TeamProvider>
<Component {...pageProps} />
</TeamProvider>
</AuthGuard>
</AuthWrapper>
</FirebaseAppProvider>
);
}In my page component, I try to retrieve the user, but on the initial render the user is undefined. This results in useIdtokenResult throwing an error (Error: you must provide a user) since no user is given and that is required. I need useIdTokenResult because the component needs those values at a later stage.
export default function EditRouteForm() {
const { data: user } = useUser();
const { data: idTokenResult } = useIdTokenResult(user as User, false, {
initialData: { claims: { group: "", roles: [] } },
});
const { group, roles } = idTokenResult.claims
/* ...... */
}Expected behavior
Because of my auth guard in the AuthCheck component, I'm expecting useUser to always return an user.
Actual behavior
The initial render of useUser always returns undefined.
jthetzel
Metadata
Metadata
Assignees
Labels
No labels