0
我正在使用Laravel社交網站啓用社交登錄。用戶從社交網站返回後,我將以/dashboard/id
等形式重定向到儀表板頁面。
現在,當我直接關閉此儀表板頁面,並在瀏覽器中重新打開登錄頁面(url: auth/login)
。它開始重定向到默認/home
。但有線的是,它沒有通過默認的getLogin()方法,所以我在AuthController中設置的$redirectPath
根本不起作用。
在sociallite中,我使用Auth::login()
方法來驗證用戶。
Laravel版本是5.1。
任何人都可以解釋這背後的邏輯是什麼?爲什麼不調用getLogin方法?
社會名流回調:
public function handleProviderCallback()
{
$user = Socialite::with('facebook')->user();
$authuser = $this->findOrCreateUser($user);
Auth::login($authuser, true);
//todo: here it should direct to lobby.
return redirect()->intended('/lobby/'.$authuser->id);
}
AuthController:
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & auth Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
protected $redirectTo = '/';
protected $redirectPath = '/lobby';
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}