manchenkoff / nuxt-auth-sanctum

Nuxt module for Laravel Sanctum authentication
https://manchenkoff.gitbook.io/nuxt-auth-sanctum/
MIT License
153 stars 18 forks source link

[Question] No Sanctum token cookie is saved when using token mode in Safari #114

Closed michaeldojcar closed 3 months ago

michaeldojcar commented 3 months ago

Hi, thanks for nice module. I am struggling with the new token mode.

Describe the bug

When I try to log in to app with token mode in current Safari, it won't save Sanctum token cookie and /api/user request throws error 401 Unauthenticated. In Chrome the token cookie is saved and user can login and call /api/user route without any problems.

To Reproduce

Steps to reproduce the behavior:

Try to login in Safari. Mode: token is set in nuxt.config.ts.

Expected behavior

In chrome token is saved correctly and everything works right.

Screenshots

Chrome cookie is saved correctly:

Snímek obrazovky 2024-06-22 v 18 01 18

In Safari nothing appear in cookies:

Snímek obrazovky 2024-06-22 v 18 06 04 Snímek obrazovky 2024-06-22 v 18 08 45

Module information

export default defineNuxtConfig({
    devtools: {enabled: true},
    css: ['~/assets/scss/main.scss'],
    ssr: false,

    postcss: {
        plugins: {
            tailwindcss: {},
            autoprefixer: {},
        },
    },

    modules: ["nuxt-auth-sanctum"],

    sanctum: {
        baseUrl: 'http://localhost:8000',
        redirect: {
            onLogin: '/', // Custom route after successful login
            onAuthOnly: '/login',
            onGuestOnly: '/',
            onLogout: '/login',
        },
        endpoints: {
            login: '/api/login',
            logout: '/api/logout',
            user: '/api/user',
        },
        globalMiddleware: {
            enabled: true,
        },
        mode: 'token'
    },
})

Nuxt environment:

michaeldojcar commented 3 months ago

Edit: It is working on production, so maybe it's related to my local environment.

manchenkoff commented 3 months ago

Hey @michaeldojcar, I tried to reproduce it in Safari, but no luck 😞 I would suggest checking Safari security-related settings or so because I believe it has nothing to do with the module, especially since you mentioned that in Chrome and Prod it's alright.

manchenkoff commented 3 months ago

Closing due to inactivity