jeudi 9 septembre 2021

login through specific guard using socialite in laravel

I have this function for google login

function :

  public function loginWithGoogle()
    { 
        try {
            $googleUser = Socialite::driver('google')->user();
            $user = User::where('google_id', $googleUser->id)->first();

            if($user){
                Auth::login($user);
                return redirect('/home');
            }

            else{
                $createUser = User::create([
                    'name' => $googleUser->name,
                    'email' => $googleUser->email,
                    'google_id' => $googleUser->id,
                    'password' => encrypt('test@123')
                ]);

                Auth::login($createUser);
                return redirect('/home');
            }

        } catch (Exception $exception) {
            dd($exception);
        }
    }

but i have created a specific guard for user login :

   'user' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

how i will change the guard to user when i login in the application through socialite Any suggestion Thanks.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3yXx3JJ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire