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?
Update(solution) :
I found that should change logout
to SignOut
in __construct()
method in LoginController
method :
public function __construct()
{
$this->middleware('guest')->except('logout');
}