Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSRF token mismatch #34

Open
LeonBuchner opened this issue Jul 18, 2023 · 2 comments
Open

CSRF token mismatch #34

LeonBuchner opened this issue Jul 18, 2023 · 2 comments

Comments

@LeonBuchner
Copy link

LeonBuchner commented Jul 18, 2023

Hey,
everything is working on localhost but as soon as I deploy my API and my Client to production it will throw the following error:

419 CSRF token mismatch

My Urls:

Client (NuxtJS): crm.domain.de
API: api.domain.de

My nuxt.config.ts

  ssr: false,
  css: ['~/assets/css/main.css'],
  routeRules: {
    '/': { redirect: '/login'},
},
   modules: [
    'nuxt-sanctum-auth'
    // ...
  ],
  nuxtSanctumAuth: {
    token: false, // set true to use jwt-token auth instead of cookie. default is false
    baseUrl: 'https://api.domain.de',
    endpoints: {
      csrf: '/sanctum/csrf-cookie',
      login: '/login',
      logout: '/logout',
      user: '/api/user'
    },
    csrf: {
      headerKey: 'X-XSRF-TOKEN',
      cookieKey: 'XSRF-TOKEN',
      tokenCookieKey: 'nuxt-sanctum-auth-token'
    },
  },
  devtools: { enabled: true },
    postcss: {
      plugins: {
        tailwindcss: {},
        autoprefixer: {},
      },
    },
})

My .env file:

FRONTEND_URL=https://crm.domain.de
SESSION_DOMAIN=crm.domain.de,api.domain.de
SANCTUM_STATEFUL_DOMAINS=crm.domain.de,api.domain.de

Any ideas how to fix it?

@kreejzak
Copy link
Collaborator

@theimerj any idea?

@theimerj
Copy link

theimerj commented Jul 19, 2023

@LeonBuchner on our projects we use it just like this:

SESSION_DOMAIN=.domain.com
SANCTUM_STATEFUL_DOMAINS=.domain.com

Also please double check that you set up everything correctly following the docs: https://laravel.com/docs/10.x/sanctum#installation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants