Gmail auth firebase not working in release flutter web

Viewed 236

I implemented google sign-in and it works really fine with debug mode but the moment I build the release version of my web app:

flutter web --release

You may check at https://decentralpeople.web.app/

It doesn't work. Plus, it doesn't show any error logs when I used:

flutter run -d edge --release

Release Logs

No error no nothing is being shown

enter image description here

Code (BloC Implementation)

Cubit

 Future<void> googleSignIn() async {
    emit(state.copyWith(
      socialAuthState: const SocialAuthLoading(),
    ));
    try {
      final data = await repo.googleSignIn();
      repo.isLoggedIn = true;
      emit(state.copyWith(
        socialAuthState: SocialAuthSuccess(data: data),
      ));
    } catch (e) {
      emit(state.copyWith(
        socialAuthState: SocialAuthFailed(message: e.toString()),
      ));
    }
  }

Data provider

static Future<UserData> googleSignIn() async {
    try {
      final googleUser = await GoogleSignIn().signIn();
      final googleAuth = await googleUser.authentication;

      final creds = GoogleAuthProvider.credential(
        accessToken: googleAuth.accessToken,
        idToken: googleAuth.idToken,
      );

      await _firebaseAuth.signInWithCredential(creds);

      final _userData = {
        "fullName": googleUser.displayName,
        "email": googleUser.email,
        "photo": googleUser.photoUrl,
        "provider": "google",
      };

      await _hive.put('user', _userData);

      return UserData.fromMap(_userData);
    } on FirebaseAuthException catch (e) {
      throw Exception(e.message);
    }
  }

Call at Front-end

CustomButton(
  btnWidth: Responsive.isDesktop(context)
      ? _size.width * 0.1
      : _size.width * 0.15,
  btnHeight: 45.5,
  btnOnPressed: () async {
    await authCubit.googleSignIn();
  },
  btnColor: const Color(0xffea4335),
  btnText: BlocListener<AuthCubit, AuthState>(
    listener: (context, state) {
      if (state.socialAuthState
          is SocialAuthSuccess) {
        Navigator.pushNamed(context, '/home');
      }
    },
    child: FittedBox(
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: const [
          Icon(
            FontAwesomeIcons.google,
            size: 22.0,
          ),
          SizedBox(
            width: 8.0,
          ),
          Text(
            "Google",
            style: kb3,
          )
        ],
      ),
    ),
  ),
),
1 Answers

Found the Answer

Step 1 : Get the CLIEND ID from GCP

Step 2: Add CLIENT ID in web/index.html

Add the clientID in web/index.html with meta tag like this:

<meta name="google-signin-client_id" content="someNumberHere-08d5a3p60m4ov8nac9hc96mrknsg68tu.apps.googleusercontent.com">

Step 3: Add the CLIENT ID & SECRET ID in Firebase

  • Add clientID and clientSecret in Firebase > Authentication > Sign-in Method

enter image description here

Related