strapi icon indicating copy to clipboard operation
strapi copied to clipboard

Nuxt 3 Cookie Disappears on page reload

Open rrubio opened this issue 1 year ago • 6 comments

On user login, the cookie gets set. However, on page refresh the cookie is deleted. Also, the expiry doesn't appear be to taking place. This is my nuxt.config. Any ideas.

On the following post they suggested upgrading strapi and nuxt, which i've tried, with the same outcome - https://github.com/nuxt-modules/strapi/pull/354

Version

@nuxtjs/strapi: 4.13.6 nuxt: 3.7.4

  runtimeConfig: {
    strapi: {
      url: 'https://login.7da2-202-129-81-163.ngrok-free.app',
      prefix: '/api',
      version: 'v4',
      cookie: {
        path: '/',
        maxAge: 60 * 60 * 24 * 30, // 30days login time
      },
      cookieName: 'strapi_jwt',
    },

I have also tried setting manually after login, but no luck -

        const { login } = useStrapiAuth()

        try {
            const response = await login({ identifier: identifier, password: password })
            await useCookie('strapi_jwt', { 
              maxAge: 60 * 60 * 24 * 7,
              path: '/'
            })            

            return response
        } catch (e) {            
            throw e
        }

rrubio avatar Jan 04 '24 23:01 rrubio

I have updated to version 1.10.1 and it's working already "@nuxtjs/strapi": "^1.10.1",

FlambeSk avatar Jan 09 '24 14:01 FlambeSk

Thank you. I'll test it in the next few days and confirm.

rrubio avatar Jan 11 '24 12:01 rrubio

Happens the same on 1.12.0

Pijuli avatar Jun 28 '24 11:06 Pijuli

i have the sme case.. is this problem fixed or not, if it fixe please tell me how to fix it..?

Jupriadi avatar Jul 24 '24 01:07 Jupriadi

The Problem is, that SSR overrides the cookie. Don't know how to circumvent that, but disabling SSR works for me.

To disable SSR, just add / set ssr: false in nuxt.config.ts

fanvyr avatar Jul 31 '24 18:07 fanvyr