I am trying to hide one of my routes in NextJS behind firebase Auth. I am storing a token in the context and retrieving the token in getServerSideProps. This works in development but once deployed to Vercel it fails. I see the cookie is there after logging in but the try block fails.
I'm wondering if it's a race condition in the production env but I am using async await.
Here is the bloc that is failing.
export async function getServerSideProps(context) {
//console.log(context)
try {
const cookies = nookies.get(context);
//const cookies = Cookies.get(context);
const token = await verifyIdToken(cookies.token);
const {uid, email} = token;
//console.log("Token in vendors: ", token);
return {
props: {
session: `Email: ${email} IUD: ${uid}`
}
}
} catch (err) {
context.res.writeHead(302, {location: "/"}); //login //change to welcome page
context.res.end();
return (
{ props: [] }
)
}
}
I am using nookies and I even tries switching to cookie-js as someone suggested. Any help would be greatly appreciated.
here is the repo: https://github.com/craigbauerwebdev/next-tartanbook
The token is set here: https://github.com/craigbauerwebdev/next-tartanbook/blob/master/components/Auth/Auth.js
The Token is being retrieved here: https://github.com/craigbauerwebdev/next-tartanbook/blob/master/pages/vendors/index.js