I got a problem.Now i can login and get token but cannot enter to middleware jwt (i though cannot send token to middleware)
My routes
Route::group([ 'prefix' => 'user', 'middleware' => 'user', 'providers' => 'jwt'], function ($router) { //
Route::get('/home', 'Auth\LoginController@info');
});
My middleware user
public function handle($request, Closure $next)
{
$this->checkForToken($request); // Check presence of a token.
try {
if (!$this->auth->parseToken()->authenticate()) { // Check user not found. Check token has expired.
throw new UnauthorizedHttpException('jwt-auth', 'User not found');
}
return $next($request); // Token is valid. User logged. Response without any token.
} catch (TokenExpiredException $t) { // Token expired. User not logged.
try {
$newtoken = $this->auth->refresh(); // Get new token.
Auth::guard('api')->onceUsingId($this->auth->manager()->getPayloadFactory()->buildClaimsCollection()->toPlainArray()['sub']);
} catch (JWTException $e) {
throw new UnauthorizedHttpException('jwt-auth', $e->getMessage(), $e, $e->getCode());
}
}
$response = $next($request);
return $this->setAuthenticationHeader($response, $newtoken); // Response with new token on header Authorization.
}
And my setting header authorization in vuejs
axios.defaults.headers.common['Authorization'] = 'Bearer' + Vue.localStorage.get('token');
========================================== i can access user/home but need to change to
Route::get('/home/{token?}', 'Auth\LoginController@info');
when i send token,can access data
i want to know why ?? someone can help me??
sorry i not good an english
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire