I have enabled the anonymous sign in method in firebase project. and this is the code I am trying to make an anonymous login:
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. ${e.code}");
}
}
I do have added this code in my main function:
await Firebase.initializeApp(
name: 'test',
options: DefaultFirebaseOptions.currentPlatform,
).catchError((e) {
print('FB ERROR: $e');
});
But still I am getting an error when I do try to sign in it gives an error:
Ignoring header X-Firebase-Locale because its value was null.
I/flutter (32729): Unknown error. admin-restricted-operation.
I have tried to search out a lot but couldn’t any thing related
2
Answers
Can you change your code in main.dart page like this?
if your problem is not solved if initializeApp() contains in multiple places can you remove them?
For help: This is how I use this method in my projects.
This code is my anonymous sign-in method (auth_service.dart):
Code of my login page (login_view.dart):
Since I’m using the provider package here,
Provider.of<AuthService>(context,listen: false).signInAnonymously();
I wrote it this way. You can also use it directly assignInAnonymously();
.I hope I have helped. Enjoy your work.