Search code examples
facebooklaravellaravel-5laravel-5.5laravel-socialite

Socialite redirect the user after successful facebook registeration


I'm using Laravel 5.5 and using Socialite to register users via facebook, this is my handleProviderCallback

public function handleProviderCallback(Request $request)
{
  $state = $request->get('state');
  $request->session()->put('state',$state);
  session()->regenerate();
  $user = Socialite::driver('facebook')->user();
  $userInsert = new User();
  $userInsert->name = $user->getName();
  $userInsert->email = $user->getEmail();
  $userInsert->password = bcrypt('password');
  $userInsert->save();
  return redirect()->guest('admin/dashboard');
}

the user is inserted successfully in the database but i can't redirect him to "admin/dashboard" how to do it.


Solution

  • Try to force the user to login before redirect him/her to dashboard:

    Insert this:

    \Auth::login($userInsert, true);
    

    Before:

    return redirect()->guest('admin/dashboard');