-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useUser() returns undefined unexpectedly on initial render #582
Comments
Hi @wieringen, does this happen with ReactFire We have a test to guard against this exact issue, so I'm a little surprised it is happening at all: Lines 320 to 327 in 363c7c6
|
Actually, I wonder if this could be related to mixing Something like: const { status, data: signInCheckResult } = useSigninCheck();
const { data: user } = useUser();
if (status === "loading") {
return props.fallback;
}
console.assert(user === signInCheckResult.user, user, signInCheckResult.user); |
I'm using the latest version 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");
}
} |
We had a similar issue with
Pinning to 4.2.2 resolved the error, with
|
Had the same issue, user was undefined on initial render. What solved it for me was adding See also following comment at the (deprecated) AuthCheck:
|
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.
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.
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.
The text was updated successfully, but these errors were encountered: