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

DigiProduct's avatar

Get Auth id of an API user

How can I get the Auth:id of the authorised API user?

I'm using Laravel Passport ,and so the user is authorised for the API by the Token ...

But I want to return only the data that is "owned" by that userid ...

So, how can I get that userid when they access the the API with a token?

0 likes
1 reply
slev1n's avatar
slev1n
Best Answer
Level 4

It's depends on your current guard (config/auth.php) -> web, api or custom.

You can do like this

$user = auth('api')->user();
$id = auth('api')->id();

Please or to participate in this conversation.