How to get user only with middleware?(prevent duplicate request) #216
Replies: 2 comments
-
The middleware is only used on routes, but the user token is stored in some place as per your configuration files, for example, I use Redis the store this information so to retrieve this data accordingly with claims it'll query the Redis database. Might be your configured file is to use your database SGBD as a driver. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your reply! After a couple of days, I found the cause. Anyway thanks and sorry to disturb you :) |
Beta Was this translation helpful? Give feedback.
-
I noticed a strange thing using the laravel/debugbar.
If you pass a bearer token to the api request, there will always be a request to the database to receive user from token. If you use the Check middleware, then the request is duplicated.
When I disable all middleware from the request,also remove all code from function and left only empty response(in order to make sure that nothing causes this request) , 1 request to get the user remains.
I can't figure out how to turn it off to get the user only when middleware is used
i also tried to change in config/auth.php api guard from jwt to session(just to make sure), and after this user request dissapear. Also if you remove the token from request, user db request also dissapear.
In theory, this suggests that the user's request occurs somewhere when receiving (checking) the token, and unfortunately I cannot find where exactly.
I will be very grateful for any help
Beta Was this translation helpful? Give feedback.
All reactions