Auth with NuxtJS ant Sanctum on Valet setup

Viewed 259

Hours wasted but still can't understand why I'm only able to run authorization with NuxtJS and Laravel Sanctum only through http://localhost, every other time I'm getting 419 token mismatches.

I know that for authorization to work properly frontend and backend should be on the same TLD *.tld.test my setup is (I even went further and made the same domain but the different port to serve FE/BE, doesn't help too, also countless other combinations):

FE app -> app.backend.test:3000
BE app -> backend.test

I have all settings related to CORS, no CORS errors here.

Other important settings:

SESSION_DRIVER=cookie

In sanctum.php

'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
        '%s%s',
        'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1,backend.test,backend.test:3000,app.backend.test,app.backend.test:3000',
        env('APP_URL') ? ','.parse_url(env('APP_URL'), PHP_URL_HOST) : ''
    ))),

By the way, I'm using Valet, so every *.test is pointed to 127.0.0.1 automatically through dnsmasq, If that matters somehow.

And the only way I can run this thing is to use localhost:3000 and localhost:8000 by running PHP artisan serve and changing above mentioned settings to "localhost".

So http://localhost:3000 is nuxt serve and http://localhost:8000 is PHP artisan serve.

0 Answers
Related