Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pypy's avatar
Level 1

Laravel Sanctum: (Frontend & Backend with different IP Address) Error: Login CSRF Token mismatch

Having csrf token mismatch error in login with Nuxt and Laravel Sanctum. When I change the domains of both app (frontend & backend) into localhost, login works perfectly. But if I set:

FRONTEND_URL=https://127.0.0.11

BACKEND_URL=https://127.0.0.10

CSRF token mismatch error occurs. Is there any workaround?

0 likes
4 replies
vincent15000's avatar

When using Laravel Sanctum, backend and frontend have to be on the same domain. So using different IP addresses won't work.

2 likes
OussamaMater's avatar

@vincent15000 This is valid only when using sessions*, otherwise you can use sanctum to authenticate third party and mobile applications via tokens and add that frontend domain to the cors config.

2 likes
vincent15000's avatar

@OussamaMater Yes sure, but the CSRF token mismatch with different IP addresses for back and front let me think that @pypy is trying to use a session authentication.

1 like
OussamaMater's avatar

@vincent15000 Yes correct, he is using session, I just wanted to add the information for people who read this and maybe think that they MUST have the same domain in ALL cases.

1 like

Please or to participate in this conversation.