nuxt-community / auth-module

Zero-boilerplate authentication support for Nuxt 2
https://auth.nuxtjs.org
MIT License
1.93k stars 925 forks source link

Already logged in on Laravel sub-domain #1740

Open smilingpeanut opened 2 years ago

smilingpeanut commented 2 years ago

I have a Laravel app at my.domain.com and Nuxt app at www.domain.com. The auth module is working well. I can log in via Nuxt using the Laravel Sanctum scheme. What I'm trying to figure out is how to register that the user is logged in if the user logged in via the Laravel app instead of the Nuxt app.

So if someone logs in via the Laravel app at my.domain.com, how can that cascade to www.domain.com when the user visits it next? Thanks!

antandev commented 2 years ago

hello @smilingpeanut,

i have similar application like yours, where i used laravel as my api + admin panel and serve on my subdomain.

i have some explanation on this issues 1337 although i am not good at explaining.

so basically this module only fetch user api when loggedIn state are true. and that is the problem for your and my case. to solve that problem my solution was to manually fetch user using fetch or axios when loggedIn state is false on my layout after that successfully fetch user data then call this.$auth.setUser(userData) and this.$auth.setUserToken(true). that is how to solve your problem.

hope this will help