675 questions
-1
votes
0
answers
87
views
How to authenticate API routes in Laravel 12 using Sanctum [closed]
I have a route which I wish to protect with a token, using Sanctum.
The offending route is /status, which would be accessed by /api/status.
The /foo route works fine, there is only a problem when ...
0
votes
1
answer
116
views
Laravel API returning HTML instead of JSON when served via NGINX
I’m running a Laravel backend alongside a Vue frontend on NGINX. The issue I’m facing is that my API endpoints are returning HTML instead of JSON. For example:
https://isuecampusmap.site/api/ → ...
Advice
0
votes
0
replies
48
views
How to properly build an HR Management System using Laravel (API) + Next.js (frontend) with token authentication and middleware?
I'm building an HR Management System using:
Backend: Laravel
Frontend: Next.js
Authentication(SPA): Laravel Breeze (already set up for backend)
I'm a beginner in Next.js, and I’m a bit stuck on how ...
3
votes
1
answer
135
views
Getting 401 Unauthorized when calling Laravel Sanctum API after Inertia login (React + Laravel)
I'm using Laravel 11 with Jetstream (Inertia + React) and Sanctum for authentication.
Everything works fine when logging in via the default Inertia login page, but when I try to call a protected API ...
1
vote
1
answer
105
views
Why does my Register route keep returning 401 Unauthorized?
Frontend part kept popping 401 Unauthorized, so I switched to Postman to just test the API.
Just to mention I am using Sanctum for API auth.
It keeps throwing 401 error, but Register route is not ...
2
votes
1
answer
254
views
How to disable laravel sanctum redirect to login page
How do I fix the standard behavior of laravel sanctum. I use sanctum for a SPA application.
I'm only interested in the backend component of the framework, without the blade pages.
Route::get('/...
4
votes
1
answer
631
views
Laravel 12 Sanctum + React Vite blocked by CORS policy
I created an app using Laravel 12 + Sanctum and React.
Locally in my laptop my app is working properly then I upload it to a Windows Server (IIS). With the same port 5173 of React and port 82 for the ...
0
votes
1
answer
117
views
protect laravel 12 api routes using middleware
I have an SPA in Laravel 12 using vue and Sanctum for auth.
I want to create a middleware to protect the the api routes /api/admin/*
I have created a middleware Admin.php
public function handle(...
0
votes
0
answers
82
views
Can't call protected routes from Laravel 12 using fetch in Server Component in Next.js 15
I am using Laravel sanctum SPA authentication and everytime I use axios with config of withCredentials:true and withXSRFToken:true and call protected routes from the laravel api, it works perfectly ...
0
votes
1
answer
94
views
I am getting unauthenticated response from api/user while using react and laravel sanctum
I am building a website using React for the frontend and Laravel for the backend.
I wrote a React Context for authentication, which sends a request to the /api/user endpoint. This endpoint is ...
3
votes
2
answers
241
views
Nuxt 3 and Laravel 12 Sanctum SPA Authentication Generating New Session Every Request
Here's the situation I'm facing in my project:
Stack:
Backend: Laravel 12 (session driver: database, Sanctum SPA authentication)
Frontend: Nuxt 3
Backend runs at: localhost:8000
Frontend runs at: ...
0
votes
1
answer
224
views
Why is auth:sanctum used on api routes and not on web routes?
I am using Laravel sanctum SPA auth to protect my routes/api.php routes. Instead of manually implementing the routes and controllers for authentication, I am using Laravel Fortify.
Now Fortify adds ...
1
vote
1
answer
212
views
Laravel sanctum SPA authentication with multiple different user models
I'd like to implement authentication in Laravel 11/12. I am using Laravel as an API that is consumed by two Angular SPA's on the same domain (different subdomains): call it the admin frontend and the ...
0
votes
0
answers
42
views
Laravel Sanctum middleware ignores subdomain
I'm trying to make a Laravel project (v 12) to serve 3 subdomains with completely separated authentication systems (Separated users model, users table, sessions table, etc.) using Laravel Sanctum. ...
0
votes
2
answers
108
views
How to generate Laravel Sanctum tokens for users while seeding?
I have a Laravel REST API that exclusively serves authenticated users. Authentication is done via Laravel Sanctum.
Now for local development on the API, I seed the database with three users.
User::...
2
votes
2
answers
289
views
How to automatically delete Laravel Sanctum tokens when a user is deleted?
Using Laravel Sanctum it seems tedious, that I must always explicitly delete the personal access tokens, when deleting a user:
$user = User::find(123);
$user->tokens()->delete(); // ...
1
vote
1
answer
179
views
I keep getting CSRF token mismatch while trying to login with my React SPA to Laravel Sanctum API
I am trying to build authenticatio for my React SPA using Laravel Sanctum SPA, the problem is whenever I try to send a login request I keep getting "CSRF token mismatch", despite following ...
0
votes
2
answers
186
views
How can I send authenticated requests from React to a Laravel API using Sanctum?
I'm building a frontend in React.js and a backend in Laravel, and I'm trying to implement authentication using Laravel Sanctum.
I've set up the Laravel API, installed Sanctum, and configured the cors, ...
0
votes
0
answers
34
views
Auth::user() Returns null Even with Valid Token (Laravel Sanctum)
I'm working on a Laravel 11 API using Sanctum for authentication. I have a route protected by the auth:sanctum middleware, and I'm sending a valid token in the request header. However, when I try to ...
0
votes
2
answers
109
views
Deploying Laravel to a subfolder
Does Sanctum (or Laravel) cookie-based session require me to have Laravel deployed to the root folder?
Background
My application lives in a monorepo with server, client and some other folders, with ...
0
votes
1
answer
121
views
Why Laravel Sanctum still uses CSRF token for SPA auth? [closed]
With Laravel Sanctum, we have to set the SANCTUM_STATEFUL_DOMAINS environment variable to specify which domains should be treated as stateful—meaning they rely on sessions and cookies for ...
1
vote
1
answer
151
views
Sanctum expired tokens not removed from personal_access_token table when expired
I created an authentication app using Laravel API Sanctum and React.js. Now when the user is logged In the token is sent from the API with an expiration duration of 30 minutes. There are two cases ...
-1
votes
1
answer
172
views
Laravel 11 Sanctum Authentification not working with Angular 18
I'm trying to implement Sanctum authentification between laravel 11 and Angular 18 but to no eval, i tried everything i could find on forums , tutorials , chatgpt but nothing worked , this website is ...
0
votes
1
answer
154
views
Laravel 11 - Sanctum SPA session logout all devices is not working
We're trying to implement Sanctum SPA authentication (session based, not api tokens), when a user changes their password, we can't seem to log them out of other devices using Auth::logoutOtherDevices($...
3
votes
0
answers
184
views
Laravel Sanctum CSRF Token Cookies Invalid Domain with Multi-tenant SPA Setup
Issue
I'm building a SPA that needs to authenticate with a Laravel back-end using Sanctum. I'm using the stancl/tenancy package for multi-tenancy, where each tenant has their own subdomain. However, ...
0
votes
0
answers
124
views
Laravel 11: "Method Illuminate\Auth\RequestGuard::viaRemember does not exist" using Sanctum
I am working with Laravel 11, and I'm using Sanctum for API authentication. However, I am encountering the error:
Method Illuminate\Auth\RequestGuard::viaRemember does not exist.
This error occurs ...
0
votes
0
answers
120
views
Laravel Sanctum and Nuxt Auth Utils
I've started project with Laravel and Nuxt3.
But I can't use nuxt-auth-utils with sanctum. It doesn't work.
I try login, laravel return token then it processes another request - https://ecommerce.loc:...
1
vote
0
answers
92
views
Laravel 11 Sanctum Token Expiration
I'm developing an Api with Laravel 11 using Sanctum as the authentication method. I've set the token expiration to 7 days and I'd like the client to receive a 401 response 'Token invalid or expired' ...
0
votes
1
answer
139
views
2 laravel projects communicating using API Sanctum?
I have two laravel projects
Bac4 laravel v.8
InfraProject laravel v.9
I want them to communicate using the Laravel Sanctum API.
I want the InfraProject to access some data in the Bac4 project and ...
0
votes
1
answer
101
views
Error in login Session store not set on request?
I have Laravel as the backend and Nuxt js as frontend i used Session Sanctum here is the set up:
in my cors.php :
'paths' => ['api/*', 'sanctum/csrf-cookie'],
'allowed_methods' => ['*'],
...
0
votes
1
answer
330
views
Laravel Sanctum Impersonate User only works for one request
I'm using Laravel Jetstream, which uses sanctum for authentication. I'm trying to build a simple impersonate feature, and I have it working 99% of the way, but I am missing something small.
If the ...
0
votes
1
answer
97
views
Bearer token not included in request header
I tried using token based auth using Laravel Sanctum, using Nuxt JS on Front End
Laravel Framework 11.29.0 (http://192.168.10.11:8000)
Nuxt 3.13.2 running in (http://192.168.10.11:3000)
And ...
0
votes
0
answers
66
views
Laravel get token with SQL Server
I'm trying to make an authentication login with laravel Sanctum and get create the token using SQL Server and I have the following error:
SQLSTATE[22007]: [Microsoft][ODBC Driver 17 for SQL Server][...
0
votes
1
answer
334
views
500 error when trying to log out of the vue3 laravel sanctum account
I have written an authentication form, login, registration and receipt of the user work for me, but logout does not work for me, the user can log into the account, but he can no longer log out.
So ...
1
vote
2
answers
576
views
Laravel Socialite Google OAuth with Sanctum: Session created but user_id is null after login
I'm building an API-only SPA with Laravel Sanctum and Nuxt3, using cookie-based session authentication. I’ve implemented Google OAuth using Laravel Socialite.
Here’s my current setup for the Google ...
0
votes
0
answers
64
views
Access Laravel Sanctum API from a basic HTML Form
When I access my Laravel sanctum API with Postman, it works properly. This is the code of routes\api.php:
use App\Http\Controllers\PoiController;
use App\Http\Controllers\AuthController;
use ...
1
vote
1
answer
446
views
Laravel reverb auth with sanctum
I have Laravel reverb private channel and when try to listen data not return also when make it as public channel data returned successfully:
In my event I make broadcast with static data but not ...
0
votes
1
answer
77
views
How do I protect my endpoints from data harvest?
Sorry for my lack of CSRF understanding, but shouldnt this Sanctum feature make it pretty hard to access my endpoints from other than my frontend app?
Everything is working in my frontend (SPA), ...
0
votes
0
answers
149
views
Laravel sanctum during testing: "Session store not set on request."
This error happens very often for people, most of the time because SANCTUM_STATEFUL_DOMAINS is not set correctly. I did set it correctly for local development but the error happens during testing, e.g....
4
votes
1
answer
533
views
Laravel sanctum and default `auth:web`
Just because my understanding of the sanctum package seems to be wrong in some places:
1) I thought by reading the config of sanctum it will use the default
/*
|----------------------------------------...
0
votes
0
answers
249
views
Accessing API server through ngrok causing 419
(I have been digging this for over 24 hours now and have tried everything that I could find online), so there is a lot of detail, but I'll try to keep it as objective as I can).
I'm trying to access ...
0
votes
1
answer
73
views
auth:sanctum middleware on logout not set user_id field null session
When I log out with auth:sanctum middleware , the user_id field on sessions tabel is not set to null, unlike when I don't use it.
Route::post('/logout', function (Request $request) {
Auth::guard('...
2
votes
0
answers
102
views
How to use Cookies based session authentication (Sanctum from Laravel 11) with Vue3
I have two platforms: one built with pure PHP and session-based authentication, and the other using Laravel 11 and Vue 3.
We have the authentication logic implemented on the first platform, and I'm ...
1
vote
0
answers
135
views
Next.js server action authentication laravel breeze api
I want to use Next.js application as SPA in an integrated way with Laravel API. There is breeze-next library for this, but the operations performed here are client-side. I want to do auth operations ...
0
votes
1
answer
127
views
Google Authentication Avatar
public function callback()
{
$googleUser = Socialite::driver('google')->user();
$user = User::updateOrCreate(
['google_id' => $googleUser->id],
...
0
votes
0
answers
107
views
Laravel Sanctum: CORS error, no Access-Control-Allow-Origin header when unauthenticated
I am using Laravel 10 backend with Angular 16 frontend
I am getting a CORS error when making a unauthenticated call. I do not get this error when there is a valid token attached to the request. I also ...
0
votes
0
answers
316
views
Laravel Sanctum 'Access-Control-Allow-Origin' Error
I'm working on a Laravel 11 project where I'm using Laravel Sanctum for authentication in my SPA (Vuejs3). My setup includes a backend and a frontend hosted on different subdomains, and I'm running ...
0
votes
1
answer
893
views
Why am I getting a 401 Unauthorized on Laravel Echo's authentication to a Private Channel?
I'm building a template project for myself, and I've got Reverb and Echo working as intended with regular channels, but when using private channels, the /broadcasting/auth route returns a 401 ...
2
votes
1
answer
486
views
Request failed with status code 419 -Nextjs and Laravel Sanctum
I have two projects, Laravel 8 and Next.js. Everything works smoothly when I send a GET request, but I encounter an error when I send a POST request. I've attempted various solutions, but the issue ...
0
votes
0
answers
39
views
access http-only cookies via javascript from php
I have a laravel function for login which creates a sanctum token once successful:
public function attempt(Request $request)
{
$validated = $request->validate([
'email' => ['required'...