app/Http/Controllers/Auth/LoginController.php
/**
     * Obtain the user information from GitHub.
     *
     * @return \Illuminate\Http\Response
     */
Obtain the user information from GitHub.
@return \Illuminate\Http\Response
Obtain the user information from GitHub . @return \ Illuminate \ Http \ Response
public function handleProviderCallback($redSocial)
    {
        console.log('entre en handle');
        $userSocial = Socialite::driver($provider)->stateless()->user();
        if ($userSocial && isset($userSocial->email) && isset($userSocial->id)) {
            $findUser = User::where('email', $userSocial->email)->first();
            if ($findUser) {
                if (Hash::check($userSocial->email . $userSocial->id, $findUser->password)) {
                    $findUser->api_token = str_random(60);
                    $findUser->save();
                    return redirect('/#/')->withCookie(cookie('authentication',
                        json_encode([
                            'api_token' => $findUser->api_token,
                            'user_id' => $findUser->id
                        ]), 8000, null, null, false, false));
                } else {
                    return redirect('/#/login')->withCookie(cookie('authentication', json_encode([
                            'error' => 'User is unavailable. Try another social account!',
                            'redirect' => '/login'
                        ]), 8000, null, null, false, false));
                }
            } else {
                $user = New User;
                $user->name = $userSocial->name;
                $user->email = $userSocial->email;
                $user->password = Hash::make($userSocial->email . $userSocial->id);
                $user->api_token = str_random(60);
                $user->save();
                return redirect('/#/')->withCookie(cookie('authentication',
                    json_encode([
                        'api_token' => $user->api_token,
                        'user_id' => $user->id
                    ]), 8000, null, null, false, false));
            }
        } else {
            return redirect('/#/login')->withCookie('authentication',
                json_encode([
                    'error' => 'User is unavailable or email field is empty. Try another social account!',
                    'redirect' => '/login'
                ]), 8000, null, null, false, false);
        }
    }
public function handleProviderCallback ( $ redSocial ) { console . log ( 'entre en handle' ) ; $ userSocial = Socialite :: driver ( $ provider ) -> stateless ( ) -> user ( ) ; if ( $ userSocial && isset ( $ userSocial -> email ) && isset ( $ userSocial -> id ) ) { $ findUser = User :: where ( 'email' , $ userSocial -> email ) -> first ( ) ; if ( $ findUser ) { if ( Hash :: check ( $ userSocial -> email . $ userSocial -> id , $ findUser -> password ) ) { $ findUser -> api_token = str_random ( 60 ) ; $ findUser -> save ( ) ; return redirect ( '/#/' ) -> withCookie ( cookie ( 'authentication' , json_encode ( [ 'api_token' => $ findUser -> api_token , 'user_id' => $ findUser -> id ] ) , 8000 , null , null , false , false ) ) ; } else { return redirect ( '/#/login' ) -> withCookie ( cookie ( 'authentication' , json_encode ( [ 'error' => 'User is unavailable. Try another social account!' , 'redirect' => '/login' ] ) , 8000 , null , null , false , false ) ) ; } } else { $ user = New User ; $ user -> name = $ userSocial -> name ; $ user -> email = $ userSocial -> email ; $ user -> password = Hash :: make ( $ userSocial -> email . $ userSocial -> id ) ; $ user -> api_token = str_random ( 60 ) ; $ user -> save ( ) ; return redirect ( '/#/' ) -> withCookie ( cookie ( 'authentication' , json_encode ( [ 'api_token' => $ user -> api_token , 'user_id' => $ user -> id ] ) , 8000 , null , null , false , false ) ) ; } } else { return redirect ( '/#/login' ) -> withCookie ( 'authentication' , json_encode ( [ 'error' => 'User is unavailable or email field is empty. Try another social account!' , 'redirect' => '/login' ] ) , 8000 , null , null , false , false ) ; } }
Obtain the user information from GitHub.
Obtain the user information from GitHub .
/* try {
            //code...

                $socialUser = Socialite::driver($redSocial)->stateless()->user();
                //dd($socialUser);


                //return $user->getEmail();

            } catch (\exception $e ) {

                return redirect('/ ');
            }
        $user = User::where('email',$socialUser->getEmail())->first();

        $socialProvider = SocialProvider::where('provider_id',$socialUser->getId())
                                        ->where('provider',$redSocial)->first();

        if (!$socialProvider) {
            # code...
            if(!$user)
            {
                $user = User::firstOrCreate(
                    ['email'=> $socialUser->getEmail()],
                    ['name'=> $socialUser->getName()],
                );


            }
            $user->SocialProvider()->Create(
                ['provider_id'=>$socialUser->getId(), 'provider' =>$redSocial,'user_id'=>$user->id,'avatar'=>$socialUser->getAvatar()]
            );
        };

        auth()->login($user);

        return redirect('/home');
        */