Reputation: 3202
i am working on laravel socialite to login using gmail.i can able to store user info and if gmail id and email already exist then it should redirect to dashboard.
public function googleCallback()
{
$user = Socialite::with('google')->user();
$email=$user->email;
$user_id=$user->id;
if(Auth::attempt(['email' =>$email,'password'=>$user_id]))
{
//return redirect('user/UserDashboard');
//return Redirect::to('user/UserDashboard');
echo "i am here";
}
}
in the above code if i use echo then it will print .suppose if redirect to dashboard it wont work.i don't know why redirect wont work for socialite.Can anyone tell where i am doing wrong ? thank you
Update: suppose if i login to my site using gmail or fb or github then data will store in my db.if that person login second time then it should redirect to user dashboard. the above code will check if auth::attempt exist or not.suppose if i print any think in inside if() block it works.suppose if i add redirect to dashboard then login through gmail and all not working
Upvotes: 1
Views: 178
Reputation: 1836
I don't know till what extent my answer would be correct but it should go somewhat like this:
public function googleCallback()
{
$user = Socialite::with('google')->user();
$email=$user->email;
$user_id=$user->id;
$user_db = \App\User::where('email', $user->email)->first();
if (count($user_db) == 1) {
echo "i am here";
} else {
// Your registration process
// With Login process i.e. auth()->attempt(YOURDATA);
}
}
This is the only way that I could have done this thing. If anything else I can help in, put it in the comment box.
Upvotes: 1
Reputation: 883
use this to redirect
return redirect()->intended('user/UserDashboard');
Upvotes: 0