我已经问过这个问题,但我仍然没有得到答案。
How to login using Github, Facebook, Gmail and Twitter in Laravel 5.1?
我能够存储数据库中gmail,github的数据。
if (Auth::attempt(['email' => $email, 'password' => $user_id]))
{
return redirect()->intended('user/UserDashboard');
}
else
{
//here i am going to insert if user not logged in already
return redirect()->intended('user/UserDashboard');
}
我的问题是,如果我回显任何数据而不是return redirect()->intended('user/UserDashboard');
,那么它就会显示出来。如果我添加重定向,那么它不起作用。
答案 0 :(得分:2)
我在使用google for oAuth时并不完全确定它是如何工作的,但我认为你想要的流程是:
假设上述方法看起来像这样。
public function google()
{
// Redirect user to google for authentication
return Socialite::driver('google')->redirect();
// In Laravel 5.0 this would be
// return Socialize::with('google')->redirect();
}
public function googleCallback()
{
// Return from google with user object
$googleUser = Socialite::driver('google')->user();
// In Laravel 5.0 the above would be
// $user = Socialize::with('google')->user();
// If user exists, retrieve the first() record,
// otherwise create a new record
$user = User::firstOrCreate([
'user_id' => $googleUser->id,
'name' => $googleUser->name,
'password' => $googleUser->id,
'email' => $googleUser->email,
'avatar' => $googleUser->avatar
]);
// Login the user
Auth::login($user, true);
// Redirect to the dashboard
return Redirect::intended('user/UserDashboard');
}