nuxt-ssr-firebase-auth.v2
nuxt-ssr-firebase-auth.v2 copied to clipboard
Does not work with nuxt generate
When I run this example with npm run dev it works as expected, but when I try it with the generated version (npm run generate) and I reload the page or open a new tab it ask me again to sign in.
I tried on netlify and locally using a local server (npm run generate && cd dist/ && python -m SimpleHTTPServer 9090)
Do you know how can I can get this to work?
I too am experiencing this issue. I have tried on Netlify and also with Firebase. Dev and build are fine, but generate is not working with page reload. The cookie is available in all instances.
in helpers/index.js
linter suggests:
Could not find a declaration file for module 'cookieparser'. '/Users/stinny/Documents/GitHub/dr3/nuxt-ssr-firebase-auth.v2/node_modules/cookieparser/js/cookieparser.js' implicitly has an 'any' type.
Try npm install @types/cookieparser if it exists or add a new declaration (.d.ts) file containing `declare module 'cookieparser';
Is this why generate is having issues with session persistence on page refresh?
I see cookieparser is 6 years without an update now so maybe this is the issue.
The issue seems to be with helpers/index.js
Replacing "function getUserFromCookie" with the code below does work with "nuxt generate" (ie: page refresh does not reset the session) BUT only on local with "nuxt start" and not on production server. :(
import jwtDecode from 'jwt-decode'
var cookieparser = require('cookieparser')
export function getUserFromCookie (req) {
if(req && req.headers && req.headers.cookie){
const parsed = cookieparser.parse(req.headers.cookie)
const accessTokenCookie = parsed.access_token
if (!accessTokenCookie) return
const decodedToken = jwtDecode(accessTokenCookie)
if (!decodedToken) return
return decodedToken
}
}
export function getUserFromSession (req) {
return req.session ? req.session.userId : ''
}
If I understood correctly to make this work there should be an interaction between the nuxt client and the nuxt server. When you use generate you get only static files once and so there will not be any interaction while you are using the application. I think there is no way around this