Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript firebase规则,允许新用户在首次登录时创建其帐户对象_Javascript_Angular_Firebase_Firebase Realtime Database_Firebase Security - Fatal编程技术网

Javascript firebase规则,允许新用户在首次登录时创建其帐户对象

Javascript firebase规则,允许新用户在首次登录时创建其帐户对象,javascript,angular,firebase,firebase-realtime-database,firebase-security,Javascript,Angular,Firebase,Firebase Realtime Database,Firebase Security,我有这个规则,它通过了模拟测试,但是客户端在成功使用google进行身份验证后出现了错误“权限被拒绝”。下面的部分规则检查users对象中的uid对象,如果它不存在,则允许创建一个对象 !(root.child('users').child(auth.uid).exists()) 整个规则如下: { "rules":{ ".read":"root.child('users').child(auth.uid).child('roles/admin').val()===true ||

我有这个规则,它通过了模拟测试,但是客户端在成功使用google进行身份验证后出现了错误“权限被拒绝”。下面的部分规则检查users对象中的uid对象,如果它不存在,则允许创建一个对象

!(root.child('users').child(auth.uid).exists())
整个规则如下:

{
  "rules":{ 
    ".read":"root.child('users').child(auth.uid).child('roles/admin').val()===true || root.child('users').child(auth.id).child('id').val()===auth.uid",
    ".write":"!(root.child('users').child(auth.uid).exists()) || root.child('users').child(auth.uid).child('roles/admin').val()===true || root.child('users').child(auth.id).child('id').val()===auth.uid",
  } 
}
角度代码:

@Effect() loginGetUserInfo$ = this.actions$.pipe(
    ofType(AuthActionTypes.AUTH_LOGIN_GET_USER_INFO),
    map((action: AuthLoginGetUserInfo) => action.user),
    exhaustMap((googleUser: User) => {
        const ref = this.db.object('users/' + googleUser.uid);
        debugger;
        return ref.valueChanges().pipe(
            map((user: User) => {
        debugger;
                if (!user) {
                    console.log("Is a new user:", googleUser);
                    //ref.set(googleUser);
                    ref.update(googleUser)
                    return new AuthLoginSuccessful(googleUser)
                }
                return new AuthLoginSuccessful(user)
            }),
            catchError(error => {debugger; return of(new AuthLoginFailure(error)) })
        )
    })
);

确切的问题是什么?你到底想干什么?你能用原子步骤分解你的需求来解释吗?如果我测试你的规则,它们似乎满足了要求(据我所知):用户第一次可以写个人资料,之后就不能再写了。我发现了。“权限被拒绝”来自读取而不是写入。我修正了读取规则,现在新用户可以创建配置文件了。