strapi icon indicating copy to clipboard operation
strapi copied to clipboard

Token cookie is not saved with Nuxt 3

Open dsciamma opened this issue 4 years ago • 6 comments

Version

@nuxtjs/strapi: 1.0.0-27336403.27afa67 nuxt: 3.0.0-27333638.5ab1816

Steps to reproduce

Use the example application to log in with strapi.

What is Expected?

The JWT token should be stored in cookies

What is actually happening?

No cookie is stored. So token cannot be reused between pages or sessions.

Workaround

I'm saving the cookie from the page after the login method. Then it can be used in other pages. I saw some messages stating useCookie cannot be used in composable right now.

dsciamma avatar Dec 29 '21 10:12 dsciamma

Hi @dsciamma,

Have you tried using the latest version of nuxt3? I think a fix has been made about this.

Let me know if it fixes your issue.

benjamincanac avatar Jan 04 '22 12:01 benjamincanac

Closing this for now, feel free to reopen if your problem persists.

benjamincanac avatar Jan 12 '22 10:01 benjamincanac

Sorry, I haven't seen your previous comment. I'll try with the new version of Nuxt3 and I'll reopen the ticket if needed.

dsciamma avatar Jan 12 '22 10:01 dsciamma

I got this issues and I followed the documentation, when I refresh the page, the user is logged out all the time

KiritoXD01 avatar Jun 15 '23 14:06 KiritoXD01

Have you tried setting the path to / or setting a maxAge?

export default defineNuxtConfig({
  strapi: {
    cookie: {
      path: '/',
      maxAge: 30 * 24 * 60 * 60
    }
  }
})

benjamincanac avatar Jun 15 '23 17:06 benjamincanac

Same for me. I don't encounter this problem in dev mode, but after building for prod,useStrapiUser() as well as useStrapiToken() returns null, although cookie is sent in the request. In the nuxt.config.js I have

strapi: {
    url: process.env.NUXT_ENV_STRAPI_API_URL,
    prefix: '/',
    version: 'v4',
    cookie: {
      path: '/',
      maxAge: 60 * 60 * 24 * 7,
      //httpOnly: true,
      //secure: true,
      sameSite: true,
    },
    cookieName: 'strapi_jwt',
    entities: ['user'],
  },

AndriiKlymchuk avatar Oct 08 '23 16:10 AndriiKlymchuk