我正在尝试编写应用程序,我有一些无法解决的安全问题,我需要帮助。
我在firebase上使用用户电话身份验证,它工作正常。现在我想知道,当用户auth被授予用户id时,它会保存在数据库中,并且工作正常。
但问题是,我使用此代码为新用户在数据库上写代码的规则是:
{
"rules": {
".write": "auth == null ",
".read": "auth == null "
}
}
此代码用于新用户注册时:
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
Firebase Ref = new Firebase( "database address" );
Firebase usersRef = Ref.child( "Users" ).child( "user_id" );
usersRef.setValue( user.getUid() );
当我使用此规则时,身份验证被拒绝:
{
"rules": {
".write": "auth != null ",
".read": "auth != null "
}
}
但是我的用户已经注册了,我获得了他的id和电话表单身份验证用户如何解决这个安全问题?
D/FirebaseAuth: Notifying id token listeners about user ( b3bizXzmH7XQfXWNvHCMVXzDHSx2 ).
D/FirebaseApp: Notifying auth state listeners.
D/FirebaseApp: Notified 0 auth state listeners.
D/PhoneAuthActivity: signInWithCredential:success
D/FirebaseAuth: Notifying id token listeners about user ( b3bizXzmH7XQfXWNvHCMVXzDHSx2 ).
D/FirebaseApp: Notifying auth state listeners.
Notified 0 auth state listeners.
D/PhoneAuthActivity: signInWithCredential:success
W/RepoOperation: setValue at /Users/user_id failed: FirebaseError: Permission denied
W/RepoOperation: setValue at /Users/user_id failed: FirebaseError: Permission denied
D/FirebaseAuth: Notifying id token listeners about user ( b3bizXzmH7XQfXWNvHCMVXzDHSx2 ).
D/FirebaseApp: Notifying auth state listeners.
D/FirebaseApp: Notified 0 auth state listeners.
D/PhoneAuthActivity: signInWithCredential:success
W/RepoOperation: setValue at /Users/user_id failed: FirebaseError: Permission denied