Update
I use this plugin to Phone auth https://ionicframework.com/docs/native/firebase-authentication. So how can I transfer that Auth details to the AngulraFireAuth?
async signIn(): Promise<void> {
await this.firebaseAuthentication.signInWithVerificationId(verificationId, securityCode);
}
auth.service.ts
onAuthStateChanged(): void {
this.firebaseAuthentication.onAuthStateChanged().subscribe((res) => {
this.zone.run(async () => {
if (res) {
// code
});
});
}
Original
I have a Firebase Storage bucket permission like so: Same for the Firestore
too.
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write:if request.auth != null;
}
}
}
Client-side code: i.e. upload an image
console.log('user', await this.afAuth.currentUser); //null
const filePath: string = `signatures/${user.uid}`;
const afUploadTask: AngularFireUploadTask = afStorageReference.putString(imageDataUrl, 'data_url');
But it fails:
vendor.js:44100 ERROR Error: Uncaught (in promise): FirebaseStorageError: {"code_":"storage/unauthorized","message_":"Firebase Storage: User does not have permission to access 'signatures/gx3TlaSFQoPhQXCnjk3QCrq2j9x1'.","serverResponse_":"{\n "error": {\n "code": 403,\n "message": "Permission denied. Could not perform this operation"\n }\n}","name_":"FirebaseError"}
So how can I configure this kind of rule with Storage? Without any rule above code is working fine.
console.log(firebase.auth().currentUser)
on the line before the upload starts, to see what the user auth state really is at that point. – Frank van Puffelen Jun 17 '20 at 22:41console.log(firebase.auth().currentUser)
statement? If so, can you update your question to show the updated code and its output? – Frank van Puffelen Jun 17 '20 at 23:00