You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am using Nextjs and firebase to build an webapp.
Expected
When a user requests the page, It will show some data about this user.
Current Way
What I did: using getServerSideProps to fetch data. It is from NextJs which will execute when the page is requested.
Here I get userIdfirst, using firebase auth. Then, I use userId to access the doc in the "users" collection . After that, I pass the data I want to props.
Question
The problem could be shown in the following images. The auth.currentUser?.uid might return string or null. But I can make sure I have logged in when testing. It should be string result.
But it popped error like below.
However, if I use string literal ID instead of above code. There is no error.
I am assume the error exist in auth.currentUser?.uid. And doc() function somehow cannot assert variable userId could be used for function param.
How do I solve this problem? Thanks for your help!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I am using
Nextjs
andfirebase
to build an webapp.Expected
When a user requests the page, It will show some data about this user.
Current Way
getServerSideProps
to fetch data. It is fromNextJs
which will execute when the page is requested.userId
first, usingfirebase auth
. Then, I useuserId
to access the doc in the "users" collection . After that, I pass the data I want toprops
.Question
The problem could be shown in the following images. The
auth.currentUser?.uid
might returnstring
ornull
. But I can make sure I have logged in when testing. It should bestring
result.But it popped error like below.
However, if I use string literal ID instead of above code. There is no error.
I am assume the error exist in
auth.currentUser?.uid
. Anddoc()
function somehow cannot assert variableuserId
could be used for function param.How do I solve this problem? Thanks for your help!
Beta Was this translation helpful? Give feedback.
All reactions