Home > other >  flutter firebase anonymously login doesn't work
flutter firebase anonymously login doesn't work

Time:10-20

I am trying to login to firebase anonymously, but it is not possible to login in any way. When I set my login function to a value, the user id is seen, but it is not seen that he is logged into the firebase. What would be the reason

class SignInScreen extends StatelessWidget {
  const SignInScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: signInAppBarColor,
        title: const Text("Flutter Lovers"),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
         
          ElevatedButton(onPressed: _anonymouslySignIn, child: Text('sign in'))
        ],
      ),
    );
  }

  void _anonymouslySignIn() async {
    var user = await FirebaseAuth.instance.signInAnonymously();
    print(user.toString());
  }
}

CodePudding user response:

Can't specifically answer this question with certainty without the requested items commented above, but I'm guessing you missed a step in either setting up Firebase in your project, or instantiating firebase. See the FlutterFire documentation for if you missed any steps:

https://firebase.flutter.dev/docs/auth/start

If you aren't getting any errors or logs when you try and sign in, I'd recommend changing your call to something like this so that you can see what's actually going wrong:

try {
  final userCredential =
      await FirebaseAuth.instance.signInAnonymously();
  print("Signed in with temporary account.");
} on FirebaseAuthException catch (e) {
  switch (e.code) {
    case "operation-not-allowed":
      print("Anonymous auth hasn't been enabled for this project.");
      break;
    default:
      print("Unknown error.");
      print(e);
  }
}

This will log the specific error that's causing it to not work.

  • Related