sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.31k stars 164 forks source link

Cookies not set if secureCookieAttribute and httpOnlyCookieAttribute is true #938

Open donn1123 opened 2 weeks ago

donn1123 commented 2 weeks ago

Environment

Reproduction

Here's my auth setup in nuxt.config

auth: { baseURL: '', globalAppMiddleware: true,

provider: {
  type: 'local',
  endpoints: {
    signIn: { path: '<api>', method: 'post' },
    getSession: { path: '<api>', method: 'get' },
  },
  token: {
    signInResponseTokenPointer: '/access',
    maxAgeInSeconds: 300,
    sameSiteAttribute: 'none',
    secureCookieAttribute: process.env.NODE_ENV === 'production',
    httpOnlyCookieAttribute: process.env.NODE_ENV === 'production',
  },
  refresh: {
    isEnabled: true,
    endpoint: { path: '<api>', method: 'post' },
    refreshOnlyToken: true,
    token: {
      signInResponseRefreshTokenPointer: '/refresh',
      refreshRequestTokenPointer: '/refresh',
      maxAgeInSeconds: 60 * 60 * 24 * 1,
      sameSiteAttribute: 'none',
      secureCookieAttribute: process.env.NODE_ENV === 'production',
      httpOnlyCookieAttribute: process.env.NODE_ENV === 'production',
    },
  },
},

},

Describe the bug

When I refresh the page it goes back to login page again. I notice that the auth.token and refresh token are not set in browser cookies. In my local or even in prod, when I set secureCookieAttribute and httpOnlyCookieAttribute to false, the tokens are added and everything works just fine. The problem only happens when I set TRUE secureCookieAttribute and httpOnlyCookieAttribute.

My backend where I call the api is using JWT and I also tried adding Set-Cookie: auth.token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...; HttpOnly; Secure; SameSite=Lax; Path=/; Expires=<some expiration date> in the login api response.

Additional context

No response

Logs

No response

julienguillot77 commented 1 day ago

I’m facing same issue. Please someone can fix it ?