@danyal14 The route that triggers the error will be the route that you requested? Or am I missing something?
Authentication Middleware & custom responses
Hi Guys,
I am referring to my previous question, that is not actually solved but marked solved by mistaken. https://laracasts.com/discuss/channels/lumen/authentication-middleware
Since Lumen has Authenticate middleware and implements check on handle method.
public function handle($request, Closure $next, $guard = null)
{
if ($this->auth->guard($guard)->guest()) {
return response('Unauthorized.', 401);
}
return $next($request);
}
That's mean every routes lies under auth middleware, if unauthenticated will get same response message "Unauthorized", where as I want to return more details depending on which route triggered this error.
Routes:
// Routes requires auth
$router->group(['middleware' => 'auth'], function () use ($router) {
$router->get('auth/logout', 'User\AuthController@logout');
$router->get('auth/verify', 'User\AuthController@verify');
$router->get('user/profile', 'User\UserController@profile');
});
$router->post('auth/login', 'User\AuthController@login');
What could be the possible solution?
@DANYAL14 - Right. So if you hit auth/verify, and it responds with Unauthorized, it’s the `auth/veri route you’re not allowed to receive.
This is how HTTP works: you send a request, you get a response.
Please or to participate in this conversation.