DEV Community

Cover image for Server Side Authentication with NextJS and Firebase

Server Side Authentication with NextJS and Firebase

Theran Brigowatz on September 02, 2020

Overview Finding a good way to add user authorization to a Firebase and Next.js app was not the easiest out there to find. So I thought ...
Collapse
 
atlanteavila profile image
Atlante Avila

Am I reading this correctly, or would this require authorization for every single page in the app? How would I then differentiate from the pages that require auth vs the ones that don't? For instance, log in or home page don't require auth, but user's profile does, how do you then redirect away from the authenticated pages?

Collapse
 
emmajnr1000 profile image
Emmanuel Uchewa

please can you share a repo for this example

Collapse
 
theranbrig profile image
Theran Brigowatz • Edited

I will try to get it up as a full working repo. Right now it is just from a project that I put together. I will try to put together a boiler plate example some time this week.

Collapse
 
emmajnr1000 profile image
Emmanuel Uchewa

please in the _app.js cookies is not defined

Collapse
 
theranbrig profile image
Theran Brigowatz • Edited

I am sorry. I will update that I used 'next-cookies' to read them.

Edit:
Updated article that _app.js should use next-cookies

Collapse
 
alpinstang profile image
John McDonald

Awesome tutorial. I needed a solution that was very small and flexible, with firestore users collection data. This is perfect!

Collapse
 
ivan_jrmc profile image
Ivan Jeremic

There is no need for cookies I think, I would also use the new getServerSideProps instead of getInitialProps.

Collapse
 
mohitgq profile image
mohitGQ

Can you give example code?

I wanted to understand, how you will get the user firebase token in server side without cookies?

Collapse
 
tcom009 profile image
Gerson Mayer

Hi, What's the firebaseToken suppose to be?

Collapse
 
agusescobar profile image
agustin

Hi! How are you? Just in case the code is in a repository?

Collapse
 
nithur profile image
Nithur

How can I use this validate function in a api route?