首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我的Firebase createUserWithEmailAndPassword函数没有注册用户

我的Firebase createUserWithEmailAndPassword函数没有注册用户
EN

Stack Overflow用户
提问于 2021-02-23 13:54:22
回答 1查看 37关注 0票数 0

我的Firebase createUserWithEmailAndPassword函数没有注册用户。该应用程序有一个注册方法,但它不起作用,相反,它需要我手动注册一个用户在Firebase身份验证页面,然后它从那里登录。

尝试登录后,我收到以下错误消息

代码语言:javascript
运行
复制
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类。

代码语言:javascript
运行
复制
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();
  }
}
EN

回答 1

Stack Overflow用户

发布于 2021-02-23 14:57:43

基本上,您希望用户注册并返回用户id,对吗?这段代码是我写的,请检查一下。

代码语言:javascript
运行
复制
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');

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66327790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档