[Vuejs]-Vue.js+Firebase: 401 error, 'unauthorized'

0👍

Authentication with access_token

Based on firbase authentication documentation, I think you must change your request URL to smth like this:

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;
  });

Authentication with ID token

Or you may use ID token authentication like this:

const token = 'token'; // get token somewhere
this.$http
  .post(`https://vuejs-blog-b91df.firebaseio.com/posts.json?auth=${token}`, this.blog)
  .then((data) => {
     console.log(data);
     this.submitted = true;
  });

Here you can find how to get ID token on client

Leave a comment