tymondesigns / jwt-auth

🔐 JSON Web Token Authentication for Laravel & Lumen
https://jwt-auth.com
MIT License
11.32k stars 1.54k forks source link

Not authenticating api.php routes requests. #2249

Closed iamrishi7 closed 8 months ago

iamrishi7 commented 8 months ago

api.php routes are returning 401 error. I have properly installed and set-up the package. All my routes under web.php file are working perfectly fine, but for api.php all routes are showing unauthenticated message for middleware auth:api. I upgraded my laravl from v10 to v11. I have used this package in other projects as well in the same manner as I am using in this one but I don't know why I am getting these errors.

Your environment

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version ^11
Package version ^2
PHP version 8.3

Steps to reproduce

Install the package for the same environment as mentioned above and follow step by step installation given in the docs. Make request to both web.php and api.php routes to fetch auth()->user().

Expected behaviour

auth()->user() should be returned in both cases.

Actual behaviour

Getting auth()->user() only in web.php routes

eznix86 commented 8 months ago

Do you send a JWT as Bearer Token ?

iamrishi7 commented 8 months ago

Yes I did

iamrishi7 commented 8 months ago

I added \App\Http\Middleware\EncryptCookies::class middleware in api array under $middlewareGroups in kernel.php file and things started working.