Hi guys,
i like to save the auth state (token and user) on the server-side so that when i refresh the page i keep the user logged in?
i tried using nuxtServerInit() like that

but when i refresh on a url that have an auth middleware, i get a redirection to login page.
Hi @aymenpeak
You need to use sessions on your server and use req.session.
You can use the express with the session middleware: https://github.com/expressjs/session
but express exclude laravel api , no?
How are you using laravel with nuxt.js exactly?
hi @Atinux
i'm implementing a single page app for streaming videos, i get all the data using laravel api, but the user needs to be authenticated to use some features,
i managed to login and get the token from the laravel server but when i refresh i loose the data saved in nuxt store.
so is there a way to the state saved even when there is a server rendering (refresh)?
thanks for asking by the way because im really strugglin^^
@aymenpeak please take a look at this example: https://github.com/nuxt/example-todomvc
Mainly to this file: https://github.com/nuxt/example-todomvc/blob/master/server.js
In this file I use the express-session middleware to keep the todos for each user, so when he refresh the page the todos are server-rendered (see demo: https://todomvc.nuxtjs.org/)
@Atinux yeah but my problem was that when i refresh my auth middleware redirect me before fetching the user data. So i fixed it by saving the user data in the cookies then retreive them in the req variable.
there is my middleware code

Thanks for helping :)
@aymenpeak Could you post an example of your code somewhere? I'm struggling with this as well. I'm using Laravel too and I've seen the auth-0 example but it's not working for me
@Atinux Are you guys planning some sort of Laranuxt at some point? That'd be awesome!
@aft3rlife I don't have experience in Laravel and last time I coded in PHP was 10 years ago, but it would be awesome to see someone porting Nuxt.js to Laravel!
@aft3rlife yeah ofc , first i get rid of some bugs then i will post it :)
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
@aft3rlife I don't have experience in Laravel and last time I coded in PHP was 10 years ago, but it would be awesome to see someone porting Nuxt.js to Laravel!