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

realtebo's avatar

Sanctum - How to allow api from ANY logged user?

i've a webapp with a single page made in vue, because it's requiring highly complicated interaction flows from users into the page.

Here my user of Laravel is already loged in.

I am using sanctum, (because I'm using backpack for laravel).

I ask you if there is a simple way to allow any logged user to be anthenticated and authorized to call any api.

we have this example route

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

In my page, using axios, I try to simply call axios.get('/user') but it returns me 'unauthorized'

I am doing api calls from same domain of webapp (so same domain of api)

Also, I added in the bootstrap.js file this line

windows.axios.defaults.withCredentials = true;

What is missing? As far as I know, every get send also all the cookies of the same domain to the server. So I expect Laravel can detected as logged the user. Why doesn't it happens?

0 likes
4 replies
henryavila's avatar

Hi, I imagine that you whant to get the user that is already autneticated on Laravel app, withou making the user manually autenticate on frontend app.

Did you found a solution? I'm trying to make the same thing. Make automatically Sanctum recognize the user already authenticated in auth()->user

realtebo's avatar

Sorry, we cannot find a solution and i the meanwhile I switched to a new branch in my office, no news for you

NCS-Thomas's avatar

Had a similar issue.

Changing my guard from web to backpack in config/santum.php fixed it for me.

1 like
JoshWegener's avatar

@NCS-Thomas thank you, I spent about 2 hours trying to solve this problem. You saved me many more hours! Thank you.

Please or to participate in this conversation.