当我尝试在Vue项目中使用post方法时:
this.$http.post("https://vuejs-blog-b91df.firebaseio.com/posts.json", this.blog).then(function(data) {
console.log(data);
this.submitted = true;}
控制台向我抛出错误:
Failed to load resource: the server responded with a status of 401 (Unauthorized)
Uncaught (in promise)
Response
body: {error: "Permission denied"}
bodyText: "{↵ "error" : "Permission denied"↵}↵"
headers: Headers {map: {…}}
ok: false
status: 401
statusText: "Unauthorized"
url: "https://project-name.firebaseio.com/posts.json"
data: (...)
__proto__: Object
我在哪里以及如何将Firebase项目apiKey和其他授权数据成功放置?
答案 0 :(得分:0)
基于firbase认证documentation,我认为您必须将请求URL更改为如下所示:
<ul>
<li v-for="(post, index) of paginatedPosts" class="post">
...
</li>
</ul>
或者您可以像这样使用ID令牌认证:
const token = 'token'; // get token somewhere
this.$http
.post(`https://vuejs-blog-b91df.firebaseio.com/posts.json?access_token=${token}`, this.blog)
.then((data) => {
console.log(data);
this.submitted = true;
});
Here,您可以找到如何在客户端上获取ID令牌