Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work with nuxt generate #4

Open
ilbonte opened this issue Jun 30, 2019 · 4 comments
Open

Does not work with nuxt generate #4

ilbonte opened this issue Jun 30, 2019 · 4 comments

Comments

@ilbonte
Copy link

ilbonte commented Jun 30, 2019

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?

@MetaBureau
Copy link

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.

@MetaBureau
Copy link

MetaBureau commented Aug 13, 2019

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.

@MetaBureau
Copy link

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 : ''
}

@ilbonte
Copy link
Author

ilbonte commented Aug 20, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants