[英]401 Unauthorized Error Using Axios and Firebase
我正在使用 firebase 并且我想从我的反应应用程序发送数据。 我安装了 Axios 然后制作了一个 Axios 组件并使用 Axios 发送数据。 但我收到 401 未经授权的错误
purchaseContinueHandler = () => {
const order = {
ingredients : this.state.ingredients,
price : this.state.totalPrice,
customer : {
name : 'Usman',
address :{
street : 'wapda town',
zipcode : '54700',
country : 'pakistan'
},
email : 'usidd@gmail.com'
},
deliveryMethod : '30minutes'
}
axios.post('/order.json',order).
then(response =>
console.log(response)).
catch(error =>
console.log(error)); // .json to be added for firebase
}
firebase的安全规则如下:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// This rule allows anyone with your database reference to view, edit,
// and delete all data in your Firestore database. It is useful for getting
// started, but it is configured to expire after 30 days because it
// leaves your app open to attackers. At that time, all client
// requests to your Firestore database will be denied.
//
// Make sure to write security rules for your app before that time, or else
// all client requests to your Firestore database will be denied until you Update
// your rules
match /{document=**} {
allow read, write: if request.time < timestamp.date(2020, 8, 25);
}
}
}
您很可能对实时数据库有一些安全规则,以防止未经身份验证的用户写入数据库。 您在问题中显示的是Firestore的安全规则,而不是Realtime Database的安全规则(它们是两种不同的数据库服务)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.