nuxt-sanctum-auth icon indicating copy to clipboard operation
nuxt-sanctum-auth copied to clipboard

User is not logged in

Open Friis1978 opened this issue 1 year ago • 4 comments

Hi, I want to be able to know whether the user is logged in, using the useAuth() function, but it seemed like the user is never logged in, when using the $sanctumAuth.login.

Im able to call the protected routes on the api, so the csrf token is working as expected, but on locale host and in production, but the user is never set, using useAuth().

What am I doing wrong? Screenshot 2023-07-27 at 11 15 55

This is the nuxt.config.js file

nuxtSanctumAuth: { token: false, baseUrl: process.env.NUXT_PUBLIC_API_URL || "https://endpoint", endpoints: { csrf: "/sanctum/csrf-cookie", login: "/login", logout: "/logout", user: "/api/v1/user", }, csrf: { headerKey: 'X-XSRF-TOKEN', cookieKey: 'XSRF-TOKEN', tokenCookieKey: 'nuxt-sanctum-auth-token', }, redirects: { home: "/", login: "/login", logout: "/", }, },

Friis1978 avatar Jul 27 '23 09:07 Friis1978

Hi, how do you call the login method? There should be no need to fetch user manually.

kreejzak avatar Aug 02 '23 18:08 kreejzak

Hi, im using a normal login function, like this: const loginSanctum = async () => { const { email, password } = form.value; try { await $sanctumAuth.login( { email, password, }, (res) => { emit("onLoggedIn"); if (redirectTo) { return location.reload(); //return router.replace(redirectTo) } else { return router.replace("/"); } } ); } catch (e) { console.log("login error", e); error.value = e?.message; }

Then I see the token afterwards as a cookie, but it seems like 'auth' is not working because when im trying to get the user it works fine, apparently the using is just not seen as logged in for 'Auth' in nuxt.

Friis1978 avatar Aug 04 '23 06:08 Friis1978

Hi, Same problem all cookies are set. But const { $sanctumAuth } = useNuxtApp() const auth = useAuth() does not have content or setting

hadimajidi avatar Aug 19 '23 22:08 hadimajidi

Hi, Same problem all cookies are set. But const { $sanctumAuth } = useNuxtApp() const auth = useAuth() does not have content or setting

Did you find solution to this?

filippo88 avatar Feb 14 '24 21:02 filippo88