You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
There seem to be an incorrecte or a non-typical configuration of cookies in your package.
When I make a request to endpoint /api/me ( with necessary cookies for authentication), I get back an Unauthorized response.
To Reproduce
Steps to reproduce the behavior:
set up sanctum on Laravel (version 10) and serve on port 8000
Additional context
I was suggested to make some changes to your package in order to authenticate user via Cookie, since apparently token-based auth is not supported.
in sanctum.php middleware was chnanged to the following:
'middleware' => [
'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class,
'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class,
'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class,
],
in config/api.php
Route::middleware('auth:sanctum')->group(function () {
// your authenticated API routes here
Route::post('login', [UserController::class, 'login']);
Route::get('me', [UserController::class, 'me']);
})->middleware('web'); //
in app/Http/Controllers/UserController.php some codes were exchanged for the following:
$plainTextToken = $user->createToken('hydra-api-token', $roles)->plainTextToken;
$cookie = cookie('hydra-api-token', $token, 60 * 24 * 7); // set the cookie for 7 days
return response()->json(['error' => 0, 'id' => $user->id, 'name' => $user->name, 'token' => $plainTextToken])->withCookie($cookie);
Describe the bug
There seem to be an incorrecte or a non-typical configuration of cookies in your package.
When I make a request to endpoint /api/me ( with necessary cookies for authentication), I get back an Unauthorized response.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I want to catch cookies from the request and authenticate users for laravel API routes
Screenshots
not neccessary at this point
Nuxt environment:
I am using the following repository:
https://github.com/manchenkoff/nuxt-auth-sanctum
Module information
Laravel environment:
FRONTEND_URL=http://localhost:3000
SESSION_DRIVER=cookie
config/cors.php
Additional context
I was suggested to make some changes to your package in order to authenticate user via Cookie, since apparently token-based auth is not supported.
in sanctum.php middleware was chnanged to the following:
'middleware' => [
'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class,
'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class,
'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class,
],
in config/api.php
Route::middleware('auth:sanctum')->group(function () {
// your authenticated API routes here
Route::post('login', [UserController::class, 'login']);
Route::get('me', [UserController::class, 'me']);
})->middleware('web'); //
in app/Http/Controllers/UserController.php some codes were exchanged for the following:
Unfortunately this didn't work.
I also followed in vain the suggestions in the following link:
https://laracasts.com/discuss/channels/laravel/authenticate-user-using-cookie-laravel-sanctum
The text was updated successfully, but these errors were encountered: