app/Http/Controllers/Auth/LoginController.php
/**
     * Obtain the user information from Google.
     *
     * @return RedirectResponse|Redirector
     */
Obtain the user information from Google.
Obtain the user information from Google .
public function handleProviderCallback()
    {
        try {
            $user = Socialite::driver('google')->user();
        } catch (Exception $e) {
            return redirect('/login');
        }
        $existingUser = User::where('email', $user->email)->first();
        if ($existingUser) {
            auth()->login($existingUser, true);
        } else {
            $newUser = User::create([
                'name' => $user->name,
                'is_admin' => false,
                'email' => $user->email,
            ]);
            auth()->login($newUser, true);
        }
        return redirect()->to('/home');
    }
public function handleProviderCallback ( ) { try { $ user = Socialite :: driver ( 'google' ) -> user ( ) ; } catch ( Exception $ e ) { return redirect ( '/login' ) ; } $ existingUser = User :: where ( 'email' , $ user -> email ) -> first ( ) ; if ( $ existingUser ) { auth ( ) -> login ( $ existingUser , true ) ; } else { $ newUser = User :: create ( [ 'name' => $ user -> name , 'is_admin' => false , 'email' => $ user -> email , ] ) ; auth ( ) -> login ( $ newUser , true ) ; } return redirect ( ) -> to ( '/home' ) ; }
Obtain the user information from Google.
Obtain the user information from Google .