Retrieving AuthUser from useAuthUser #263
-
Hello Gladly, Thanks for the best Next auth solution! I've got what I think is a really simple problem. Basically, what is the 'recommended' way to check if there is a logged-in user? Specifically, I have an 'Upvote' component. It must check whether there is a signed in user before running a API fetch in a useEffect. In the example below, AuthUser.email always returns null when I am logged in, I can't understand why. The component is wrapped in 'withAuthUser'. I've tried wrapping parent components and the parent page with withAuthUser as well but that doesn't help.
Many thanks for any advice. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Maybe the function could he running before initialisation. Have to tried to wait until |
Beta Was this translation helpful? Give feedback.
-
Hi Matt, thanks! To check if there's a logged-in user, I recommend checking if If it's still not working, please try running the example app in this repository with your own Firebase settings to see if you can get that working. |
Beta Was this translation helpful? Give feedback.
Hi Matt, thanks!
To check if there's a logged-in user, I recommend checking if
AuthUser.id
is set. Also, youruseEffect
hook is missingAuthUser
as a dependency, so like @shreyas-jadhav mentioned, it's probably running before the Firebase client has initialized.If it's still not working, please try running the example app in this repository with your own Firebase settings to see if you can get that working.