0

我使用社交名流成功登录了我的 Laravel 应用程序。我也正在注销,但再次访问该页面以使用谷歌登录,它会自动验证用户身份而不要求用户交互。

这些是路线:

Route::get('/redirect', 'Auth\LoginController@redirectToProvider');
Route::get('/handle-login', 'Auth\LoginController@handleProviderCallback');

控制器的功能:

public function redirectToProvider()
{
    return Socialite::driver('google')->redirect();
}

public function handleProviderCallback()
{
    try {
        $user = Socialite::driver('google')->user();
    } catch (\Exception $e) {
        return redirect('/login');
    }
    $existingUser = \App\User::where('email', $user->email)->first();
    if($existingUser){
        Auth::login($existingUser);
    } else {
        $newUser = new \App\User;
        $newUser->name = $user->name;
        $newUser->email = $user->email;
        $newUser->googleId = $user->id;
        $newUser->save();              
        Auth::login($newUser);
    }
    return redirect()->to('/home');
}

public function logout() {
    Auth::logout();
    Session::flush();
    return redirect('/');
}

我的问题是注销用户从 Laravel 注销,但是如果我再次访问该路由/redirect,用户将自动登录,我想避免它,但要求用户再次执行社交登录。

注意:我看到使用 google 登录时,登录在 google.com 上也有效,所以我猜想注销在我的域上工作,但在 google.com 上保持有效。

4

0 回答 0