Replies: 4 comments 4 replies
-
For now, for everyone struggling with the integration of firebase and next.js I recommend taking a look on this blog: https://parondeau.com/blog/server-auth-firebase-nextjs |
Beta Was this translation helpful? Give feedback.
-
Made an example of how to use firebase auth with nextjs, based on the with-iron-session. Instead of getinitialprops that most examples used, this uses getServerSideProps. Hopefully it's easy to understand, let me know if any questions https://github.com/hajola/nextjs-firebase-authentication |
Beta Was this translation helpful? Give feedback.
-
I looked at your example @hajola, thank you for that! I also updated myself on everything that is going on with Next.js updates and changes. The only thing that bothers me is that, I would really love to have the " Because... I found out that I can't use cookies in And actually, there is an optional So the last decision that I need to make is whether to break and get rid of automatic static optimization for above mentioned code convenience (if e.g. developing authorization-heavy webapp) or whether to shift my thinking and recognize that on some pages I might not need to be aware of currently logged user and on the others I would just wrap individual pages into some HOC that would include the session. If one has a dashboard or some header with user profile etc., I can't really imagine the latter. So perhaps this might be the right case not to use the automatic static optimization. [Is this a good, practical and intended way to think about it?] |
Beta Was this translation helpful? Give feedback.
-
Not sure if this will help you but I made this demo recently - hope it's useful! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Kind greetings gentlemen,
I'm trying to understand the code of
with-firebase-authentication-serverless
example and I do struggle understanding some parts, especially in the schematic of how data (token) are being traversed across next.js application.I have a header that shows on every page of the application and it's different on logged in and logged out states.
I intend to use
withAuthUser.js
wrapper to wrap the whole_app.js
, so the app checks on each page whether there exists a session in the cookie and if not it callsuseFirebaseAuth()
on client, sending a request to/api/login
and therefore updating, getting the session in the process. Consequently I intend to wrap Header inContext.Consumer
to obtain theAuthUserInfo
.The first doubt I have is, why do I need to call
useFirebaseAuth()
(inwithAuthUser.js
) on each request of page, even though I might have a session's data already? Isn't that an unnecessary call on each page's render?The second doubt I have is, the meaning of
withAuthUserInfo
wrapper; if I understand correctly, the whole wrapper is just about getting the data from the Context, am I correct? There is nothing more in there. What confuses me there is just the line ofconst AuthUserInfo = get(ctx, 'myCustomData.AuthUserInfo', null);
. Aren't we gettingAuthUserInfo
inwithAuthUser.js
wrapper and usingContext
already? Is it purposeful redundancy or am I missing some point in here?Thank you kindly for the work you did put into example as well as for the explanations and patience! Appreciated.
Beta Was this translation helpful? Give feedback.
All reactions