'Missing or insufficient permissions. request.auth seems to be null
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' } }
Solution 1:[1]
The built-in DataTables buttons don't support exporting a single column as a plain text file. You can however achieve this by defining your own button with a custom action.
The snippet below should achieve what you are looking for, it can be added to the buttons array passed to DataTable on setup. This adds a button named 'TXT' which takes the filtered values from the first column in the table, joins then with CR+LF, and then triggers a download of the result as a .txt file.
{
text: 'TXT',
action: function (e, dt, node, config) {
// Generate the text to be exported
// Please note...
// - This only takes column 0
// - The output is filtered based on the applied search
// - This doesn't include the header or footer
// - This uses CR+LF line endings
let text = dt.columns(0, { search: 'applied' }).data().toArray()[0].join('\r\n');
// Add an element to the page contianing the encoded txt to download
// click the element to trigger the download, then remove the element
let element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', 'data.txt');
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
}
A working example can be seen at https://jsfiddle.net/a3eucptL/.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chris C |
