So, I’ve been struggling hard with this error… let me explain my scenario first:
These are my firebase storage rules:
rules_version = "2";
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
// allow read, update, create: if true;
// allow read, write: if request.auth != null;
allow read, create, update: if request.auth != null;
}
}
}
And this is my code when uploading the image:
async saveGuestSignature(signature: string) {
const commonStore = useCommonStore();
const authStore = useAuthStore();
const storageRef = ref(storage, `/guests-signatures/${commonStore.hotel}/${authStore.uid}.png`);
const b64 = signature.substring(signature.indexOf(',') + 1);
try {
const snapshot = await uploadString(storageRef, b64, 'base64');
return await getDownloadURL(snapshot.ref)
} catch (error) {
await saveErrorLog(commonStore.hotel, authStore.uid, 'saveSignature', error);
Notify.create({
type: 'negative',
timeout: 15000,
icon: 'mdi-alert',
message: `Un error sucedió al intentar guardar la firma: ${error}`,
actions: [
{
label: 'Ok',
color: 'white',
handler: () => {
/* ... */
}
}
]
});
return null;
}
},
commonStore.hotel
and authStore.uid
are indeed defined, and the user is certaninly authenticated before this upload operation is performed.
Most of the time, it works, but for some users, I’m getting this error randomly:
FirebaseError: Missing or insufficient permissions.
This function as you can see uploads the image (base64 string) and returns the downloadURL or if fails it should return null, in order to save this to the database.
I’ve tried changing the rules, and it seems that if read, write: true
is set to allow all read and write operations, it works, but this is obviously not the idea.
I know it seems like it can be an authentication issue, but, I’m pretty sure the user is authenticated, since there are more operations to the firestore database for example which needs the user to be authenticated too and those work perfectly.