Firebase 错误:用户无权访问
Posted
技术标签:
【中文标题】Firebase 错误:用户无权访问【英文标题】:Firebase Error: User does not have access 【发布时间】:2021-08-18 04:47:58 【问题描述】:我正在开发一个 snapchat 克隆,我想使用在网络摄像头上单击的图像存储在 firestore 中并将其用作预览。该代码是完美的,但它显示了与 firebase 相关的错误。我不知道该怎么做。 这是我的代码
import "./Preview.css"
import resetCameraImage, selectCameraImage from './../features/cameraSlice';
import useSelector, useDispatch from 'react-redux';
import useHistory from 'react-router';
import CloseIcon from "@material-ui/icons/Close";
import TextFieldsIcon from "@material-ui/icons/TextFields";
import CreateIcon from "@material-ui/icons/Create";
import NoteIcon from "@material-ui/icons/Note";
import MusicNoteIcon from "@material-ui/icons/MusicNote";
import AttachFileIcon from "@material-ui/icons/AttachFile";
import CropIcon from "@material-ui/icons/Crop";
import TimerIcon from "@material-ui/icons/Timer";
import SendIcon from "@material-ui/icons/Send";
import v4 as uuid from "uuid";
import db, storage from "./firebase";
import firebase from 'firebase';
function Preview()
const cameraImage = useSelector(selectCameraImage);
const history = useHistory();
const dispatch = useDispatch();
useEffect(() =>
if (!cameraImage)
history.replace('/');
, [cameraImage, history]);
const closePreview = () =>
dispatch(resetCameraImage());
const sendPost = () =>
const id = uuid();
const uploadTask = storage.ref(`posts/$id`).putString(cameraImage, "data_url");
uploadTask.on('state_changed', null, (error) =>
// error function
console.log(error);
,
() =>
// complete function
storage.ref('posts').child(id).getDownloadURL().then((url) =>
db.collection('posts').add(
imageUrl: url,
username: "PAPA React",
read: false,
//profilePic,
timestamp: firebase.firestore.FieldValue.serverTimestamp(),
);
history.replace('/chats');
);
);
;
return (
<div className="preview">
<CloseIcon className="preview__close" onClick=closePreview/>
<div className="preview__toolbarRight">
<TextFieldsIcon />
<CreateIcon />
<NoteIcon />
<MusicNoteIcon />
<AttachFileIcon />
<CropIcon />
<TimerIcon />
</div>
<img src=cameraImage />
<div className="preview__footer" onClick=sendPost >
<h2>Send Now</h2>
<SendIcon fontSize="small" className="preview__sendIcon" />
</div>
</div>
)
export default Preview
抛出错误
我的 Firebase 规则设置
替代方法出现同样的错误
替代方法出现同样的错误
【问题讨论】:
【参考方案1】:错误表明用户无权访问您的 Firebase 存储。为 Firebase 存储添加规则以授予用户访问权限。例如:
service firebase.storage
match /b/bucket/o
match /allPaths=**
allow read, write;
【讨论】:
这是正确的做法吗-rules_version = '2'; service cloud.firestore match /databases/database/documents match /document=** allow read, write; service firebase.storage match /b/bucket/o match /allPaths=** allow read, write;
请检查我在新图像中显示的步骤仍然得到相同的错误。不知道该怎么做。提前致谢。
您似乎将此配置覆盖到您的 Firestore 规则中。 Firebase 存储有自己的规则配置,转到您的 Firebase 控制台,选择项目,然后单击存储并转到规则面板。以上是关于Firebase 错误:用户无权访问的主要内容,如果未能解决你的问题,请参考以下文章
上传图片和 Firebase 显示“用户无权访问此对象”,即使存储设置是公开的
用户无权访问 gs://xxxx.appspot.com/(null)