React app in vercel with Laravel as REST Api and Sanctum for authentication return unauthenticated in production

156 Views Asked by At

Please help on this ,very sorry since i know there are many similar question like this but already tried many of them. Okay i have a react app hosted in vercel with domain like my-app.vercel.app and i also have a server that hosted laravel application that use for rest api. my backend have real domain attached to. i am using sanctum as the authentication method for laravel. im using api.php for all my routes but it seems any request on route inside middleware('auth:sanctum') below

Route::middleware('auth:sanctum')->group(function () {
    Route::post('/signout', [AuthController::class, 'signout']);
});

will return unauthenticated, i already tried many ways inlucing

set SANCTUM_STATEFUL_DOMAINS=my-app.vercel.app,*.vercel.app

set SESSION_DOMAIN=my-app.vercel.app

already send the Bearer token in Authorization headers for request.

already modified the cors.php file many times

already uncomment code in http/kernel.php

\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,

additional question, do i need to specify the port too since i deploy app on vercel so i dont have the port in url.

0

There are 0 best solutions below