丢失或不足的权限。请求。auth似乎是无效的
我实施了以下安全规则:
match /client/{clientId} {
allow read: if request.auth != null;
allow update, delete,create : if request.auth != null && request.auth.uid == clientId;
//allow create: if request.auth != null;
match /notifications/{notificationId} {
allow read,delete,update: if request.auth != null && request.auth.uid == clientId;
}
match /pointsHistory/{pointHistoryId} {
allow read,create: if request.auth != null && request.auth.uid == clientId;
}
match /subscribedTopics/{subscribedTopicId} {
allow read,create,delete: if request.auth != null && request.auth.uid == clientId;
}
match /userSavedAlerts/{userSavedAlertId} {
allow read,write: if request.auth != null && request.auth.uid == clientId;
}
match /userSavedPosts/{userSavedPostId} {
allow read,write: if request.auth != null && request.auth.uid == clientId;
}
}
在我的app.js上,我添加了此信息以检查用户是否已经登录:
const unlisten = auth().onAuthStateChanged((user) => {
if (user && auth().currentUser) {
setUserAuthData(user);
var db = firebase.firestore();
var docClientRef = db.collection("client").doc(auth().currentUser.uid);
docClientRef
.get()
.then((clientDoc) => {
if (clientDoc.exists) {
console.log("client doc exists: ", clientDoc.data());
const userData = clientDoc.data();
}
// getting “Missing or insufficient permissions.” Trying to read from clients collections
})
.catch((error) => {
console.log("error ", error);
});
}
return () => {
unlisten();
};
}, []);
我会收到以下错误消息:丢失或不足的权限。 request.auth似乎是null
。如何解决此错误?我检查了其他堆栈溢出答案,但没有任何帮助。 Firebase似乎是无效的。我在testflight上测试了释放应用,并在iPhone设备上的XCode上进行了调试。没有任何作用
编辑:打印Onauthstatatechanged:
'user onUserChanged', { _auth:
{ _app:
{ _name: '[DEFAULT]',
_deleted: false,
_deleteApp: [Function: bound deleteApp],
_options:
{ databaseURL: '***********',
projectId: '*******',
gaTrackingId: null,
appId: '********************',
messagingSenderId: '***********',
apiKey: '*****************',
storageBucket: '********' },
_automaticDataCollectionEnabled: true,
_initialized: true,
_nativeInitialized: true },
_nativeModule:
{ createUserWithEmailAndPassword: [Function],
linkWithCredential: [Function],
reauthenticateWithCredential: [Function],
signInAnonymously: [Function],
signInWithCredential: [Function],
signInWithCustomToken: [Function],
signInWithEmailAndPassword: [Function],
signInWithEmailLink: [Function],
updatePhoneNumber: [Function],
addAuthStateListener: [Function],
addIdTokenListener: [Function],
applyActionCode: [Function],
checkActionCode: [Function],
confirmPasswordReset: [Function],
confirmationResultConfirm: [Function],
delete: [Function],
fetchSignInMethodsForEmail: [Function],
getIdToken: [Function],
getIdTokenResult: [Function],
reload: [Function],
removeAuthStateListener: [Function],
removeIdTokenListener: [Function],
sendEmailVerification: [Function],
sendPasswordResetEmail: [Function],
sendSignInLinkToEmail: [Function],
setAutoRetrievedSmsCodeForPhoneNumber: [Function],
setLanguageCode: [Function],
setTenantId: [Function],
signInWithPhoneNumber: [Function],
signOut: [Function],
unlink: [Function],
updateEmail: [Function],
updatePassword: [Function],
updateProfile: [Function],
useDeviceLanguage: [Function],
useEmulator: [Function],
verifyBeforeUpdateEmail: [Function],
verifyPasswordResetCode: [Function],
verifyPhoneNumber: [Function],
APP_USER:
{ '[DEFAULT]':
{ metadata: { lastSignInTime: 1652986981780, creationTime: 1609348971231 },
providerData:
[ { email: '*****@gmail.com',
phoneNumber: null,
photoURL: '*************',
displayName: '**** ****',
uid: '107327466708257974027',
providerId: 'google.com' } ],
phoneNumber: null,
photoURL: '********',
displayName: '*** ***',
email: '****@gmail.com',
uid: 'W81uqWYK6SOfl6ZC1yKPqgOAU382',
tenantId: null,
isAnonymous: false,
emailVerified: true,
providerId: 'firebase' } },
APP_LANGUAGE: { '[DEFAULT]': null },
getConstants: [Function] },
_customUrlOrRegion: undefined,
_config:
{ statics:
{ AppleAuthProvider: [Function: AppleAuthProvider],
EmailAuthProvider: [Function: EmailAuthProvider],
PhoneAuthProvider: [Function: PhoneAuthProvider],
GoogleAuthProvider: [Function: GoogleAuthProvider],
GithubAuthProvider: [Function: GithubAuthProvider],
TwitterAuthProvider: [Function: TwitterAuthProvider],
FacebookAuthProvider: [Function: FacebookAuthProvider],
OAuthProvider: [Function: OAuthProvider],
PhoneAuthState:
{ CODE_SENT: 'sent',
AUTO_VERIFY_TIMEOUT: 'timeout',
AUTO_VERIFIED: 'verified',
ERROR: 'error' } }
I implemented the following security rules:
match /client/{clientId} {
allow read: if request.auth != null;
allow update, delete,create : if request.auth != null && request.auth.uid == clientId;
//allow create: if request.auth != null;
match /notifications/{notificationId} {
allow read,delete,update: if request.auth != null && request.auth.uid == clientId;
}
match /pointsHistory/{pointHistoryId} {
allow read,create: if request.auth != null && request.auth.uid == clientId;
}
match /subscribedTopics/{subscribedTopicId} {
allow read,create,delete: if request.auth != null && request.auth.uid == clientId;
}
match /userSavedAlerts/{userSavedAlertId} {
allow read,write: if request.auth != null && request.auth.uid == clientId;
}
match /userSavedPosts/{userSavedPostId} {
allow read,write: if request.auth != null && request.auth.uid == clientId;
}
}
On my app.js I added this to check if a user is already logged in:
const unlisten = auth().onAuthStateChanged((user) => {
if (user && auth().currentUser) {
setUserAuthData(user);
var db = firebase.firestore();
var docClientRef = db.collection("client").doc(auth().currentUser.uid);
docClientRef
.get()
.then((clientDoc) => {
if (clientDoc.exists) {
console.log("client doc exists: ", clientDoc.data());
const userData = clientDoc.data();
}
// getting “Missing or insufficient permissions.” Trying to read from clients collections
})
.catch((error) => {
console.log("error ", error);
});
}
return () => {
unlisten();
};
}, []);
I get the following error message: Missing or insufficient permissions. request.auth seems to be null
. How can I resolve this error? I checked other stack overflow answers but nothing helped. Auth is seems to be null for firebase. I tested release app on TestFlight and debug on Xcode on iPhone device. Nothing works
Edit: printing the onauthstatechanged:
'user onUserChanged', { _auth:
{ _app:
{ _name: '[DEFAULT]',
_deleted: false,
_deleteApp: [Function: bound deleteApp],
_options:
{ databaseURL: '***********',
projectId: '*******',
gaTrackingId: null,
appId: '********************',
messagingSenderId: '***********',
apiKey: '*****************',
storageBucket: '********' },
_automaticDataCollectionEnabled: true,
_initialized: true,
_nativeInitialized: true },
_nativeModule:
{ createUserWithEmailAndPassword: [Function],
linkWithCredential: [Function],
reauthenticateWithCredential: [Function],
signInAnonymously: [Function],
signInWithCredential: [Function],
signInWithCustomToken: [Function],
signInWithEmailAndPassword: [Function],
signInWithEmailLink: [Function],
updatePhoneNumber: [Function],
addAuthStateListener: [Function],
addIdTokenListener: [Function],
applyActionCode: [Function],
checkActionCode: [Function],
confirmPasswordReset: [Function],
confirmationResultConfirm: [Function],
delete: [Function],
fetchSignInMethodsForEmail: [Function],
getIdToken: [Function],
getIdTokenResult: [Function],
reload: [Function],
removeAuthStateListener: [Function],
removeIdTokenListener: [Function],
sendEmailVerification: [Function],
sendPasswordResetEmail: [Function],
sendSignInLinkToEmail: [Function],
setAutoRetrievedSmsCodeForPhoneNumber: [Function],
setLanguageCode: [Function],
setTenantId: [Function],
signInWithPhoneNumber: [Function],
signOut: [Function],
unlink: [Function],
updateEmail: [Function],
updatePassword: [Function],
updateProfile: [Function],
useDeviceLanguage: [Function],
useEmulator: [Function],
verifyBeforeUpdateEmail: [Function],
verifyPasswordResetCode: [Function],
verifyPhoneNumber: [Function],
APP_USER:
{ '[DEFAULT]':
{ metadata: { lastSignInTime: 1652986981780, creationTime: 1609348971231 },
providerData:
[ { email: '*****@gmail.com',
phoneNumber: null,
photoURL: '*************',
displayName: '**** ****',
uid: '107327466708257974027',
providerId: 'google.com' } ],
phoneNumber: null,
photoURL: '********',
displayName: '*** ***',
email: '****@gmail.com',
uid: 'W81uqWYK6SOfl6ZC1yKPqgOAU382',
tenantId: null,
isAnonymous: false,
emailVerified: true,
providerId: 'firebase' } },
APP_LANGUAGE: { '[DEFAULT]': null },
getConstants: [Function] },
_customUrlOrRegion: undefined,
_config:
{ statics:
{ AppleAuthProvider: [Function: AppleAuthProvider],
EmailAuthProvider: [Function: EmailAuthProvider],
PhoneAuthProvider: [Function: PhoneAuthProvider],
GoogleAuthProvider: [Function: GoogleAuthProvider],
GithubAuthProvider: [Function: GithubAuthProvider],
TwitterAuthProvider: [Function: TwitterAuthProvider],
FacebookAuthProvider: [Function: FacebookAuthProvider],
OAuthProvider: [Function: OAuthProvider],
PhoneAuthState:
{ CODE_SENT: 'sent',
AUTO_VERIFY_TIMEOUT: 'timeout',
AUTO_VERIFIED: 'verified',
ERROR: 'error' } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论