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

Aibat's avatar
Level 2

[Sanctum] Get authenticated user data without auth:sanctum middleware

Hi, I use Sanctum v4.0.3 and I can't get authenticated user data without auth:sanctum middleware, I already have Accept:application/json,Origin:'' in headers. I think I did everything in the documentation or maybe I missed something?

0 likes
4 replies
vincent15000's avatar

You want to retrieve the authenticated user without using the auth:sanctum middleware, but the users are authenticated with Sanctum ?

I don't think that it's possible.

Which documentation have you read ?

Aibat's avatar
Level 2

@vincent15000 yeah, users authenticated with sanctum and I have an api for which a user can be either authorized or unauthorized. I read official laravel doc

1 like
vincent15000's avatar

@Aibat So I just don't understand what you need ... can you explain the problem and give a concrete example ?

mishavoloshchuk's avatar

It can be done using sanctum guard: $user = auth('sanctum')->user();. If correct credentials are provided (token or cookie) it will return the authenticated user and if not - null will be returned.

2 likes

Please or to participate in this conversation.