🧔 Google Sign In

Authenticate with Google using FlutterFire

Auth Service

Implement Google Login in the auth service.

file_type_flutter services/auth.dart
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';

class AuthService {

  // ...

  Future<void> googleLogin() async {
    try {
      final googleUser = await GoogleSignIn().signIn();

      if (googleUser == null) return;

      final googleAuth = await googleUser.authentication;
      final authCredential = GoogleAuthProvider.credential(
        accessToken: googleAuth.accessToken,
        idToken: googleAuth.idToken,
      );

      await FirebaseAuth.instance.signInWithCredential(authCredential);
    } on FirebaseAuthException catch (e) {
        // handle error
    }
  }

}

Login Screen

Add Google Sign In to the login screen column.

file_type_flutter login.dart
    LoginButton(
        text: 'Sign in with Google',
        icon: FontAwesomeIcons.google,
        color: Colors.blue,
        loginMethod: AuthService().googleLogin,
    ),

Questions? Let's chat

Open Discord