我的Firebase createUserWithEmailAndPassword函数没有注册用户。该应用程序有一个注册方法,但它不起作用,相反,它需要我手动注册一个用户在Firebase身份验证页面,然后它从那里登录。
尝试登录后,我收到以下错误消息
W/System (11597): Ignoring header X-Firebase-Locale because its value was null.
I/flutter (11597): [firebase_auth/user-not-found] There is no user record corresponding to this identifier. The user may have been deleted.下面是包含Register和Sign in函数的Auth类。
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
abstract class BaseAuth {
Stream<String> get onAuthStateChanged;
Future<String> signInWithEmailAndPassword(
String email,
String password,
);
Future<String> createUserWithEmailAndPassword(
String email,
String password,
);
Future<String> CurrentUser();
Future<void> signOut();
Future<String> signInWithGoogle();
}
class Auth implements BaseAuth {
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
final GoogleSignIn _googleSignIn = GoogleSignIn();
@override
Stream<String> get onAuthStateChanged =>
_firebaseAuth.authStateChanges().map((User user) => user?.uid);
@override
Future<String> createUserWithEmailAndPassword(
String email, String password) async {
(await _firebaseAuth.createUserWithEmailAndPassword(
email: email, password: password))
.user
.uid;
}
@override
Future<String> CurrentUser() async {
return (await _firebaseAuth.currentUser).uid;
}
@override
Future<String> signInWithEmailAndPassword(
String email, String password) async {
return (await _firebaseAuth.signInWithEmailAndPassword(
email: email, password: password))
.user
.uid;
}
@override
Future<String> signInWithGoogle() {
Future<String> signInWithGoogle() async {
final GoogleSignInAccount account = await _googleSignIn.signIn();
final GoogleSignInAuthentication _auth = await account.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: _auth.accessToken, idToken: _auth.idToken);
return (await _firebaseAuth.signInWithCredential(credential)).user.uid;
}
}
@override
Future<void> signOut() {
return FirebaseAuth.instance.signOut();
}
}发布于 2021-02-23 14:57:43
基本上,您希望用户注册并返回用户id,对吗?这段代码是我写的,请检查一下。
Future<String> signUp2(String email, String password) async {
AuthResult res;
String userID;
try {
res = await _instance.createUserWithEmailAndPassword(
email: email, password: password);
userID = res.user.uid;
} catch (e) {
print(e.toString());
rethrow;
}
print(userID);
return userID;
}Authentication.signUp2('Example@example.com', '111111');
https://stackoverflow.com/questions/66327790
复制相似问题