Home > database >  Sign in/up takes so long time to load from firebase
Sign in/up takes so long time to load from firebase

Time:11-13

I'm new here and this is my first question and hopefully I get answers.

So, I'm building a flutter mobile application which is shows the home page first but if you click on profile icon you have to sign in to create profile and save your work. The problem is when I try to sign in or register it takes 3-5 min to show the home page and that's extremely long.

Here's my auth page:

class AuthService{

  final FirebaseAuth _auth = FirebaseAuth.instance;

  //creat user obj based on FirebaseUser
  UserModel? _userFromFirebaseUser (User? user){
    return user != null ? UserModel(uid: user.uid) : null;
  }  

  //sign up with email & password
  Future signUp(String email, String password) async {
    try{
      UserCredential result = await _auth.createUserWithEmailAndPassword(email: email, password: password);
      User? user = result.user;
     return _userFromFirebaseUser(user);
    } 
    on FirebaseAuthException catch (e){
      Utils.showSnackBar(e.message, Colors.red);
    }
  }


  //log in with email & password
  Future logIn(String email, String password) async {
    try{
      UserCredential result = await _auth.signInWithEmailAndPassword(email: email, password: password);
      User? user = result.user;
      return _userFromFirebaseUser(user);
    } 
    on FirebaseAuthException catch (e){
      Utils.showSnackBar(e.message, Colors.red);
    }
  }

}

and this is the sign up button function:

ElevatedButton(
                   onPressed: () async {
                      final isValid = _formKey.currentState!.validate();
                      if(!isValid) return;
                      showDialog(
                        context: context,
                        builder: (context) => const Center(child: CircularProgressIndicator()),
                      );
                      await _auth.signUp(_emailCont.text.trim(), _passwordCont.text.trim());
                      navigatorKey.currentState!.popUntil((route) => route.isFirst);
                    },
                    style: ElevatedButton.styleFrom(
                      padding: const EdgeInsets.symmetric(horizontal: 138, vertical: 13),
                      shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(30)),
                    ),
                    child: const Text(
                      'Sign Up',
                      style: TextStyle(fontSize: 22, letterSpacing: 1.5),
                    ),
                  ),

...................................................................

CodePudding user response:

Firebase is actually fast enough that a normal auth operation should execute very fast.

The only reason I could say it's the problem is the android emulator you're using on your machine. It's the issue with the recent versions of Android Emulator on the Windows platform.

so:

Change the emulator you're using to another emulator or try on a real device.

If the issue still occurs to you, downgrade the emulator version to an older version from here https://developer.android.com/studio/emulator_archive

  • Related