Laravel 5 Socialite Facebook Login Error handling on callback after user cancels app request Laravel 5 Socialite Facebook Login Error handling on callback after user cancels app request laravel laravel

Laravel 5 Socialite Facebook Login Error handling on callback after user cancels app request


in the callback(...) method you can check for presense of the 'code' input field and if it is not there redirect to back to login page with errors.

Example:

function callback(SocialAccountService $service ,Request $request) {    if (! $request->input('code')) {        return redirect('login')->withErrors('Login failed: '.$request->input('error').' - '.$request->input('error_reason'));    }    // rest of your code}    


Try catch is the best practice(it catches all exception)

 try{    $userSocial =Socialite::driver('facebook')    ->stateless()->user();    dd($userSocial); }catch (\Throwable $e) { //handle error here for php 7 or 8    } catch (\Exception $e) {   // for php 5  handle error here   }