【问题标题】:Firebase authentication problem in flutterFlutter中的Firebase身份验证问题
【发布时间】:2020-04-03 21:33:07
【问题描述】:

我在 Flutter 中遇到了 Firebase 身份验证问题。 注册成功,当我尝试登录时,按下登录按钮后出现此错误

W/Firestore(31652): (21.3.0) [Firestore]: 侦听查询(users/<...uid...>) 失败:状态{code=PERMISSION_DENIED, description=缺少或权限不足。 , 原因=null}

I/flutter (31652):PlatformException(执行获取时出错,PERMISSION_DENIED:权限缺失或不足。,null)

登录按钮代码为:

child: RaisedButton(
            child: Text("Login", style: TextStyle(
              fontSize: 18.0,
              fontFamily: 'MontserratBold',
            ),
            ),
            elevation: 5.0,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(30.0),
            ),
            color: Colors.white,
            textColor: Colors.black,
            padding: EdgeInsets.all(15.0),
            onPressed: () {
              if (_loginFormKey.currentState.validate()) {
                FirebaseAuth.instance
                    .signInWithEmailAndPassword(
                    email: emailInputController.text,
                    password: pwdInputController.text)
                    .then((currentUser) => Firestore.instance
                    .collection("users")
                    .document(currentUser.user.uid)
                    .get()
                    .then((DocumentSnapshot result) =>
                    Navigator.pushReplacement(
                        context,
                        MaterialPageRoute(
                            builder: (context) => HomePage(
                              uid: currentUser.user.uid,
                            ))))
                    .catchError((err) => print(err)))
                    .catchError((err) => print(err));
              }
            },
          ),

我还读到一个可能的解决方案是更改 firebase 中的权限,但在这种情况下,我是否允许任何用户读写?

【问题讨论】:

    标签: firebase flutter google-cloud-firestore firebase-authentication


    【解决方案1】:

    确保您在 firebase 数据库规则中允许读写 -

    【讨论】:

    • 好的,但也许这不是一个安全的解决方案。我尝试使用“允许读取,写入:如果 request.auth != null”并且有效,但这是最好的解决方案吗?足够安全吗?
    • @luc 查看this Firestore Security link,您似乎走在了正确的轨道上。对于指定的文档(您可以为firestore中的不同文档设置不同的规则)配置您的规则以按照您想要的方式读取和写入。
    猜你喜欢
    • 2021-12-09
    • 2021-04-21
    • 2020-11-27
    • 1970-01-01
    • 2020-01-23
    • 2021-03-22
    • 2021-07-08
    • 2021-06-27
    • 2019-01-05
    相关资源
    最近更新 更多