Skip to content

$request->user() or Auth::user run query each time if token doesn't exists #49201

Closed
@mnr73

Description

@mnr73

Laravel Version

10.34.2

PHP Version

8.2.12

Database Driver & Version

8.2.0

Description

sanctum version : 3.3.2

Hi, I use Laravel with Sanctum, and I've noticed that the app runs a query each time I use request()->user()
image

I found that if the saved token is incorrect or doesn't exist in the database, the user resolver runs a query each time it is called, and this is not good for performance.

Steps To Reproduce

you can run a fresh Laravel app with sanctum and set wrong token in Bearer token that not exist and use request()->user() for times.

I check app and query log with Clockwork browser extension.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions