Redirecting back to web page after User has clicked cancel

329 views Asked by At

I integrated facebook login through laravel/socialite and its working fine.

The problem is when user clicks cancel in the popup from facebook, the screen will stayed on facebook's page itself instead of redirecting to my site.

Is anywhere i need to specify the cancel redirecting url in facebook login app? I don't know how to handle this redirection.

1

There are 1 answers

0
Lucas Meine On

Just found out the answer here

Just for other who are wondering, I just figured out a way... In SocialAuthController: use Illuminate\Http\Request;

Then make constructor as:

protected $request;
public function __construct (Request $request) {
    $this->request = $request;
}

and then in callback() function:

if (isset($this->request['error'])) { 
    return redirect()->to('/error');
    //make your error route or do whatever you want!! 
} else {
    // this is my code, your actual code will go here on success
    print_r($service);
    $service = new SocialAccountService();
    $user = $service->createOrGetUser(Socialite::driver($provider));
    $providerUser = \Socialite::driver('facebook')->user();
    print_r($providerUser);
    auth()->login($user);
    return redirect()->to('/home'); 
}