From 5bf2e4ea702f40415f92ccac665884a2d85f6952 Mon Sep 17 00:00:00 2001 From: konrad Date: Tue, 9 Jan 2018 12:11:09 +0100 Subject: [PATCH] Fixed Authorization when not reloading the page after logging in --- frontend/src/components/Authors.vue | 2 +- frontend/src/components/AuthorsAddEdit.vue | 4 ++-- frontend/src/components/Books.vue | 2 +- frontend/src/components/BooksAddEdit.vue | 4 ++-- frontend/src/components/Items.vue | 2 +- frontend/src/components/ItemsAddEdit.vue | 4 ++-- frontend/src/components/Publishers.vue | 2 +- frontend/src/components/PublishersAddEdit.vue | 4 ++-- frontend/src/http-common/index.js | 5 +---- 9 files changed, 13 insertions(+), 16 deletions(-) diff --git a/frontend/src/components/Authors.vue b/frontend/src/components/Authors.vue index 85fa008..27888f4 100644 --- a/frontend/src/components/Authors.vue +++ b/frontend/src/components/Authors.vue @@ -183,7 +183,7 @@ export default { this.$on('delete-submit', function () { // Prevent deleting already deleted authors if (obj) { - HTTP.delete('authors/' + obj.id.content) + HTTP.delete('authors/' + obj.id.content, { headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')} }) .then(response => { if (response.status === 200 && response.data.message === 'success') { // Fire a notification diff --git a/frontend/src/components/AuthorsAddEdit.vue b/frontend/src/components/AuthorsAddEdit.vue index 5b5a8f5..6a56215 100644 --- a/frontend/src/components/AuthorsAddEdit.vue +++ b/frontend/src/components/AuthorsAddEdit.vue @@ -98,7 +98,7 @@ // Finally Send it // If we want to newly insert it, make a different request if (this.edit) { - HTTP.post('authors/' + this.author.id, this.author) + HTTP.post('authors/' + this.author.id, this.author, { headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')} }) .then(response => { this.loading = false @@ -117,7 +117,7 @@ this.errorNotification(e) }) } else { // insert a new author - HTTP.put('authors', this.author) + HTTP.put('authors', this.author, { headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')} }) .then(response => { this.loading = false diff --git a/frontend/src/components/Books.vue b/frontend/src/components/Books.vue index 2885277..d4067cf 100644 --- a/frontend/src/components/Books.vue +++ b/frontend/src/components/Books.vue @@ -237,7 +237,7 @@ export default { this.$on('delete-submit', function () { // Prevent deleting already deleted books if (obj) { - HTTP.delete('books/' + obj.id.content) + HTTP.delete('books/' + obj.id.content, { headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')} }) .then(response => { if (response.status === 200 && response.data.message === 'success') { // Fire a notification diff --git a/frontend/src/components/BooksAddEdit.vue b/frontend/src/components/BooksAddEdit.vue index 6410766..e51bfc3 100644 --- a/frontend/src/components/BooksAddEdit.vue +++ b/frontend/src/components/BooksAddEdit.vue @@ -288,7 +288,7 @@ // Finally Send it // If we want to newly insert it, make a different request if (this.edit) { - HTTP.post('books/' + this.book.id, this.book) + HTTP.post('books/' + this.book.id, this.book, { headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')} }) .then(response => { this.loading = false @@ -307,7 +307,7 @@ this.errorNotification(e) }) } else { // insert a new book - HTTP.put('books', this.book) + HTTP.put('books', this.book, { headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')} }) .then(response => { this.loading = false // Fire a notification diff --git a/frontend/src/components/Items.vue b/frontend/src/components/Items.vue index 8d5a639..79d94b1 100644 --- a/frontend/src/components/Items.vue +++ b/frontend/src/components/Items.vue @@ -190,7 +190,7 @@ export default { this.$on('delete-submit', function () { // Prevent deleting already deleted item if (obj) { - HTTP.delete('items/' + obj.id.content) + HTTP.delete('items/' + obj.id.content, { headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')} }) .then(response => { if (response.status === 200 && response.data.message === 'success') { // Fire a notification diff --git a/frontend/src/components/ItemsAddEdit.vue b/frontend/src/components/ItemsAddEdit.vue index 1fada65..6fc4673 100644 --- a/frontend/src/components/ItemsAddEdit.vue +++ b/frontend/src/components/ItemsAddEdit.vue @@ -109,7 +109,7 @@ // Finally Send it // If we want to newly insert it, make a different request if (this.edit) { - HTTP.post('items/' + this.item.id, this.item) + HTTP.post('items/' + this.item.id, this.item, { headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')} }) .then(response => { this.loading = false @@ -128,7 +128,7 @@ this.errorNotification(e) }) } else { // insert a new item - HTTP.put('items', this.item) + HTTP.put('items', this.item, { headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')} }) .then(response => { this.loading = false diff --git a/frontend/src/components/Publishers.vue b/frontend/src/components/Publishers.vue index 54a600b..501f582 100644 --- a/frontend/src/components/Publishers.vue +++ b/frontend/src/components/Publishers.vue @@ -182,7 +182,7 @@ export default { this.$on('delete-submit', function () { // Prevent again deleting already deleted publishers if (obj) { - HTTP.delete('publishers/' + obj.id.content) + HTTP.delete('publishers/' + obj.id.content, { headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')} }) .then(response => { if (response.status === 200 && response.data.message === 'success') { // Fire a notification diff --git a/frontend/src/components/PublishersAddEdit.vue b/frontend/src/components/PublishersAddEdit.vue index 2b32349..f22072e 100644 --- a/frontend/src/components/PublishersAddEdit.vue +++ b/frontend/src/components/PublishersAddEdit.vue @@ -89,7 +89,7 @@ // Finally Send it // If we want to newly insert it, make a different request if (this.edit) { - HTTP.post('publishers/' + this.publisher.id, this.publisher) + HTTP.post('publishers/' + this.publisher.id, this.publisher, { headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')} }) .then(response => { this.loading = false @@ -108,7 +108,7 @@ this.errorNotification(e) }) } else { // insert a new publisher - HTTP.put('publishers', this.publisher) + HTTP.put('publishers', this.publisher, { headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')} }) .then(response => { this.loading = false diff --git a/frontend/src/http-common/index.js b/frontend/src/http-common/index.js index 9df1879..297ee29 100644 --- a/frontend/src/http-common/index.js +++ b/frontend/src/http-common/index.js @@ -2,8 +2,5 @@ import axios from 'axios' let config = require('../../siteconfig.json') export const HTTP = axios.create({ - baseURL: config.API_URL, - headers: { - 'Authorization': 'Bearer ' + localStorage.getItem('token') - } + baseURL: config.API_URL })