尽管调用了登录用户,但当我重定向回应用程序时,我没有登录。我怎样才能确保在使用谷歌登录后,我已经登录到Laravel应用程序? 更新 当$user变量从google返回时,我得到一个invalidStateException Try-Catch块实际上引发了一个异常。如果我添加异常,它看起来像: 结果发现,我的.env>文件中包含了破坏它的内容: 会话\域=http://localhost:8000 。 删除此行修复了问题! /** * Obtain the user information from Google. * * @return \Illuminate\Http\Response */ public function handleProviderCallback() { try { $user = Socialite::driver('google')->user(); } catch (\Exception $e) { return redirect('/login'); } // check if they're an existing user $existingUser = User::where('email', $user->email)->first(); if($existingUser){ // log them in auth()->login($existingUser, true); } else { // create a new user $newUser = new User; $newUser->name = $user->name; $newUser->email = $user->email; $newUser->google_id = $user->id; $newUser->avatar = $user->avatar; $newUser->avatar_original = $user->avatar_original; $newUser->save(); auth()->login($newUser, true); } return redirect()->to('/home'); } 尽管调用了登录用户,但当我重定向回应用程序时,我没有登录。我怎样才能确保在使用谷歌登录后,我已经登录到Laravel应用程序? 更新 当$user变量从google返回时,我得到一个InvalidStateException Try-Catch块实际上引发了一个异常。如果我添加异常,它看起来像: .环境 SESSION_DOMAIN=http://localhost:8000 删除此行修复了问题!
尽管调用了登录用户,但当我重定向回应用程序时,我没有登录。我怎样才能确保在使用谷歌登录后,我已经登录到Laravel应用程序?
更新
当$user变量从google返回时,我得到一个invalidStateException
invalidStateException
Try-Catch块实际上引发了一个异常。如果我添加异常,它看起来像: 结果发现,我的.env>文件中包含了破坏它的内容: 会话\域=http://localhost:8000 。 删除此行修复了问题! /** * Obtain the user information from Google. * * @return \Illuminate\Http\Response */ public function handleProviderCallback() { try { $user = Socialite::driver('google')->user(); } catch (\Exception $e) { return redirect('/login'); } // check if they're an existing user $existingUser = User::where('email', $user->email)->first(); if($existingUser){ // log them in auth()->login($existingUser, true); } else { // create a new user $newUser = new User; $newUser->name = $user->name; $newUser->email = $user->email; $newUser->google_id = $user->id; $newUser->avatar = $user->avatar; $newUser->avatar_original = $user->avatar_original; $newUser->save(); auth()->login($newUser, true); } return redirect()->to('/home'); } 尽管调用了登录用户,但当我重定向回应用程序时,我没有登录。我怎样才能确保在使用谷歌登录后,我已经登录到Laravel应用程序? 更新 当$user变量从google返回时,我得到一个InvalidStateException Try-Catch块实际上引发了一个异常。如果我添加异常,它看起来像: .环境 SESSION_DOMAIN=http://localhost:8000 删除此行修复了问题!
Try-Catch块实际上引发了一个异常。如果我添加异常,它看起来像:
结果发现,我的.env>文件中包含了破坏它的内容:
会话\域=http://localhost:8000 。
。
删除此行修复了问题! /** * Obtain the user information from Google. * * @return \Illuminate\Http\Response */ public function handleProviderCallback() { try { $user = Socialite::driver('google')->user(); } catch (\Exception $e) { return redirect('/login'); } // check if they're an existing user $existingUser = User::where('email', $user->email)->first(); if($existingUser){ // log them in auth()->login($existingUser, true); } else { // create a new user $newUser = new User; $newUser->name = $user->name; $newUser->email = $user->email; $newUser->google_id = $user->id; $newUser->avatar = $user->avatar; $newUser->avatar_original = $user->avatar_original; $newUser->save(); auth()->login($newUser, true); } return redirect()->to('/home'); } 尽管调用了登录用户,但当我重定向回应用程序时,我没有登录。我怎样才能确保在使用谷歌登录后,我已经登录到Laravel应用程序? 更新 当$user变量从google返回时,我得到一个InvalidStateException Try-Catch块实际上引发了一个异常。如果我添加异常,它看起来像: .环境 SESSION_DOMAIN=http://localhost:8000 删除此行修复了问题!
删除此行修复了问题!
/** * Obtain the user information from Google. * * @return \Illuminate\Http\Response */ public function handleProviderCallback() { try { $user = Socialite::driver('google')->user(); } catch (\Exception $e) { return redirect('/login'); } // check if they're an existing user $existingUser = User::where('email', $user->email)->first(); if($existingUser){ // log them in auth()->login($existingUser, true); } else { // create a new user $newUser = new User; $newUser->name = $user->name; $newUser->email = $user->email; $newUser->google_id = $user->id; $newUser->avatar = $user->avatar; $newUser->avatar_original = $user->avatar_original; $newUser->save(); auth()->login($newUser, true); } return redirect()->to('/home'); }
当$user变量从google返回时,我得到一个InvalidStateException
InvalidStateException
.环境
SESSION_DOMAIN=http://localhost:8000
SESSION_DOMAIN