Laravel集成Facebook登录时跳过登录表单直接重定向至回调URL问题
Laravel集成Facebook登录异常:未显示登录表单直接重定向到回调URL
问题详情
- Laravel网站触发Facebook登录时,未加载Facebook登录表单,直接重定向至
.env配置的回调URL - 使用Postman调用同一重定向接口
facebookRedirect(地址:https://www.cheerzclub.com/auth/facebook),能正常返回Facebook登录页面 - 回调接口地址:
https://www.cheerzclub.com/auth/facebook/callback
控制器代码
class SocialController extends Controller { public function facebookRedirect() { return Socialite::driver('facebook')->redirect(); } public function loginWithFacebook(Request $r) { if (!$r->has('code') || $r->has('denied')) { return redirect('/'); } try { $user = Socialite::driver('facebook')->user(); } catch (Exception $e) { $user = Socialite::driver('facebook')->stateless()->user(); } $isUser = User::where('fb_id', $user->id)->first(); if (!$isUser) $isUser = User::where('email', $user->email)->first(); if (!$isUser) $isUser = User::where('email', $user->id)->first(); if ($isUser) { Auth::login($isUser); return redirect('/dashboard'); } else { $createUser = User::create([ 'name' => $user->name, 'email' => $user->email ? $user->email : $user->id, 'fb_id' => $user->id, 'email_verified_at' => now(), 'password' => Hash::make('SLogin#123') ]); Auth::login($createUser); return redirect('/dashboard'); } } }
补充信息
已附上浏览器Network标签页截图和Postman截图用于说明问题现象,请求排查该异常原因。
内容的提问来源于stack exchange,提问作者M G
相关产品推荐
相关产品推荐

