[英]Laravel 5.2 Multi Auth not loggin in
I am using laravel 5.2 and I am trying to log in with more than one auth guard but only the default is working. 我正在使用laravel 5.2,并且尝试使用多个身份验证保护登录,但只有默认设置有效。
This is my code. 这是我的代码。
Guards 逆天
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins'
]
],
Providers 供应商
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
],
Authenticate Middleware 认证中间件
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->guest()) {
if ($request->ajax() || $request->wantsJson()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('login');
}
}
return $next($request);
}
Routes 路线
Route::get('/foo', function(){
if (Auth::guard('web')->attempt(['email' => 'bale@mail.com', 'password' => 'gareth'])){
return redirect('/');
}else{
return 'No!';
}
});
Route::get('/bar', function(){
if (Auth::guard('admin')->attempt(['email' => 'lionel@mail.com', 'password' => 'password'])){
return redirect('/');
}else{
return 'No!';
}
});
Both routes return true when the attempt method is called but only the web guard actually logs a user in but if i switch the default guard to admin, the admin guard works and the web guard doesn't. 当调用try方法时,两个路由都返回true,但是只有Web Guard实际登录了用户,但是如果我将默认Guard切换为admin,则该admin Guard起作用,而Web Guard则不起作用。
Can someone help me in solving this? 有人可以帮我解决这个问题吗?
I found a github repo that solved my problem. 我找到了解决我问题的github存储库。 https://github.com/gregoryduckworth/laravel-multi-auth
https://github.com/gregoryduckworth/laravel-multi-auth
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.