Firebase存储身份验证不起作用

时间:2020-05-19 16:49:43

标签: firebase firebase-authentication firebase-storage firebase-security

我只是想让规则是,如果用户通过了身份验证,那么他们可以写。当我尝试从网站上载图片到图库时,我收到一条错误消息,说我未经授权。我已经设置了身份验证并可以正常工作。这是我的规则:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

这是我的图片上传代码:

imgUploadHandler = () => {
        const image = this.props.imageUpload;
        const uploadTask = storage.ref(`/Gallery/${image.name}`).put(image);
        uploadTask.on('state_changed',
            (snapshot) => {
                // Progress function
                const progress = Math.round((snapshot.bytesTransferred / snapshot.totalBytes) * 100);
                this.setState({ progress });
            }, 
            (error) => {
                // Error function
                console.log(error);
            }, 
            () => {
                // Complete function
                storage.ref('Gallery').child(image.name).getDownloadURL()
                .then(URL => {
                    const imageData = { imgURL: URL, name: image.name, width: "400"}
                    this.props.onImageUploaded(URL);
                    this.imgSelectedHandler(URL);
                    Axios.post(`/Gallery.json?auth=${this.props.token}`, imageData);
                })
            })
    }

0 个答案:

没有答案