manchenkoff / nuxt-auth-sanctum

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

The cookie "sanctum.token.cookie" was rejected because a non-HTTPS cookie cannot be set as "secure". #226

Open OrPh4ns opened 4 days ago

OrPh4ns commented 4 days ago

Expected behavior

Login without errors

Actual behavior

The cookie "sanctum.token.cookie" was rejected because a non-HTTPS cookie cannot be set as "secure".

### On Login and can't redirect to the homepage on logging in

in Browser with German language

cook

Module information

// REPLACE WITH YOUR FILE CONTENT!
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  ssr: false,
  compatibilityDate: '2024-04-03',
  devtools: { enabled: true },
  modules: ['@pinia/nuxt','nuxt-auth-sanctum','nuxt-feather-icons'],
  sanctum: {
    proxy: true,
    baseUrl: 'http://localhost:8000/',
    mode: "token",
    redirectIfAuthenticated: false,
    redirectIfUnauthenticated: true,
    endpoints: {
      csrf: '/sanctum/csrf-cookie',
      login: '/api/auth/login',
      logout: '/api/auth/logout',
      user: '/api/profile',
    },

    // csrf: {
    //   cookie: 'XSRF-TOKEN',
    //   header: 'X-XSRF-TOKEN',
    // },
    redirect: {
      keepRequestedRoute: false,
      onLogin: '/',
      onLogout: '/auth/logout',
      onAuthOnly: '/auth/login',
      onGuestOnly: '/',
    },
    globalMiddleware: {
      enabled: true,
      allow404WithoutAuth: false,
    },
  }
})

Nuxt environment:

Laravel environment:

OrPh4ns commented 4 days ago

login works only on localhost but on uploading to dev server with ip xx.xx.xx.x:3000 and backend with same ip xx.xx.xx.x:8000 it does not work

OrPh4ns commented 4 days ago

even success login on localhost i get this message before redirecting to home page

The cookie "sanctum.token.cookie" does not have a valid value for the "SameSite" attribute. Soon, cookies without the "SameSite" attribute or with an invalid value for it will be treated as "Lax". This will stop the cookie from being sent to contexts belonging to a third party. If your application needs the cookie in these contexts, please add the "SameSite=None" attribute to it. For more information about the "SameSite" attribute, see https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite.

manchenkoff commented 3 days ago

Hey @OrPh4ns, it looks like you are using HTTP protocol instead of HTTPS on your server, please check Laravel configuration in session.php and set secure to false. Otherwise, you have to use HTTPS for Nuxt/Laravel applications (for your address 10.1.80.141). Also, you should not use .localhost as your SESSION_DOMAIN, sometimes it can work localhost but better to keep it empty or use correct TLD.