diff --git a/src/front/src/api/articleApi.js b/src/front/src/api/articleApi.js index be2fe76..75d772a 100644 --- a/src/front/src/api/articleApi.js +++ b/src/front/src/api/articleApi.js @@ -1,12 +1,12 @@ import axios from 'axios'; +import commonUtil from "../utils/commonUtil"; function getArticles({page = 0, size = 10, q = ''}) { - const accessToken = this.$cookie.get('accessToken'); return axios({ url: '/api/articles', headers: { - 'Authorization': 'Bearer ' + accessToken, + 'Authorization': commonUtil.getAuthenticationHeaderBearer.bind(this)() }, params: { page, @@ -16,6 +16,22 @@ function getArticles({page = 0, size = 10, q = ''}) { }); } +function postArticle({title = '', content = ''}) { + + return axios({ + url: '/api/articles', + method: 'post', + headers: { + 'Authorization': commonUtil.getAuthenticationHeaderBearer.bind(this)() + }, + data: { + title, + content + } + }); +} + export default { - getArticles + getArticles, + postArticle } \ No newline at end of file diff --git a/src/front/src/middlewares/authentication.js b/src/front/src/middlewares/authentication.js index 094ac75..8bf8c4d 100644 --- a/src/front/src/middlewares/authentication.js +++ b/src/front/src/middlewares/authentication.js @@ -1,16 +1,12 @@ import axios from "axios"; export default async function () { - try { - const token = this.$cookie.get('accessToken'); - const result = await axios({ - method: 'get', - url: '/api/users', - headers: { - 'Authorization': 'Bearer ' + token - } - }); - } catch (e) { + await axios({ + method: 'get', + url: '/api/users', + headers: { + 'Authorization': 'Bearer ' + this.$cookie.get('accessToken') + } + }); - } } \ No newline at end of file diff --git a/src/front/src/pages/articles/List.vue b/src/front/src/pages/articles/List.vue index 9284531..f57db7a 100644 --- a/src/front/src/pages/articles/List.vue +++ b/src/front/src/pages/articles/List.vue @@ -1,5 +1,5 @@