dingo / dingo/api

“Unauthenticated” error message for logged In users in larvel 5.5

Open
#1,481 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
9.4k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

I'm using `[Dingo/api][1]` laravel package to create an API. I worked with it before and I have not this problem.

this is my routes in the `api.php` file :

$api = app('Dingo\Api\Routing\Router');
$api->version('v1', ['prefix' => 'v1', 'namespace' => 'App\Http\Controllers'], function ($api) {

$api->group(['prefix' => 'auth'], function ($api) {
$api->post('signIn', 'Auth\LoginController@signIn');
});

$api->group(['middleware' => 'api.auth'], function ($api) {
$api->get('signOut', ['uses' => 'Auth\LoginController@signOut']);

$api->get('test', function () {
return response()->json(['foo' => 'bar']);
});
});

});

`/signIn` route works fine and respond a token that can used in other protected endpoint like `/test` and `/test` directory works fine.

But I want to Sign out a user and call `/signOut` route it responses this always:

{
"success": false,
"message": "Unauthenticated.",
"status_code": 500
}

This is `signOut` method in `LoginController` :

public function signOut()
{
//return 'Hiiiii Alll';
try {
$token = \Tymon\JWTAuth\Facades\JWTAuth::getToken();
\Tymon\JWTAuth\Facades\JWTAuth::invalidate($token);
return [
'success' => true,
'message' => 'You Signed Out Successfully'
];

} catch (\Exception $e) {
return $this->response->error('Something went wrong', 404);
}
}
Even when I return a Simple string from that method it does not run, seems problem is in `['middleware' => 'api.auth']` that I used But if it's right why problem does not occurred for `test` directory that in in the same route group?

[1]: https://github.com/dingo/api

Contributor guide

Open the contributing guide

Research direction

Reproduce the protected routes from api.php, focusing on the api.auth middleware and the signOut method in LoginController. Compare the failing signOut request with the working test endpoint using the same token, then trace where the unauthenticated response is generated. Done means a valid logged-in request reaches signOut and the existing authentication behavior remains correct for the other protected route.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
api, authentication, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.