update
This commit is contained in:
@@ -1,74 +1,64 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import commonUtil from "../utils/commonUtil";
|
import commonUtil from "../utils/commonUtil";
|
||||||
|
|
||||||
function getArticles({page = 0, size = 10, q = ''}) {
|
|
||||||
|
|
||||||
return axios({
|
|
||||||
url: '/api/articles',
|
|
||||||
headers: {
|
|
||||||
'Authorization': commonUtil.getAuthenticationHeaderBearer.bind(this)()
|
|
||||||
},
|
|
||||||
params: {
|
|
||||||
page,
|
|
||||||
size,
|
|
||||||
q
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getArticle(id) {
|
|
||||||
return axios({
|
|
||||||
url: '/api/articles/' + id,
|
|
||||||
headers: {
|
|
||||||
'Authorization': commonUtil.getAuthenticationHeaderBearer.bind(this)()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function postArticle({title = '', content = ''}) {
|
|
||||||
|
|
||||||
return axios({
|
|
||||||
url: '/api/articles',
|
|
||||||
method: 'post',
|
|
||||||
headers: {
|
|
||||||
'Authorization': commonUtil.getAuthenticationHeaderBearer.bind(this)()
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
title,
|
|
||||||
content
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateArticle(id, {title = '', content = ''}) {
|
|
||||||
return axios({
|
|
||||||
url: '/api/articles/' + id,
|
|
||||||
method: 'put',
|
|
||||||
headers: {
|
|
||||||
'Authorization': commonUtil.getAuthenticationHeaderBearer.bind(this)()
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
title,
|
|
||||||
content
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeArticle(id) {
|
|
||||||
|
|
||||||
return axios({
|
|
||||||
url: '/api/articles/' + id,
|
|
||||||
headers: {
|
|
||||||
'Authorization': commonUtil.getAuthenticationHeaderBearer.bind(this)()
|
|
||||||
},
|
|
||||||
method: 'delete'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getArticles,
|
getArticles({page = 0, size = 10, q = ''}) {
|
||||||
getArticle,
|
|
||||||
postArticle,
|
return axios({
|
||||||
updateArticle,
|
url: '/api/articles',
|
||||||
removeArticle
|
headers: {
|
||||||
|
'Authorization': commonUtil.getAuthenticationHeaderBearer.bind(this)()
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
page,
|
||||||
|
size,
|
||||||
|
q
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getArticle(id) {
|
||||||
|
return axios({
|
||||||
|
url: '/api/articles/' + id,
|
||||||
|
headers: {
|
||||||
|
'Authorization': commonUtil.getAuthenticationHeaderBearer.bind(this)()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
postArticle({title = '', content = ''}) {
|
||||||
|
|
||||||
|
return axios({
|
||||||
|
url: '/api/articles',
|
||||||
|
method: 'post',
|
||||||
|
headers: {
|
||||||
|
'Authorization': commonUtil.getAuthenticationHeaderBearer.bind(this)()
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
title,
|
||||||
|
content
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
updateArticle(id, {title = '', content = ''}) {
|
||||||
|
return axios({
|
||||||
|
url: '/api/articles/' + id,
|
||||||
|
method: 'put',
|
||||||
|
headers: {
|
||||||
|
'Authorization': commonUtil.getAuthenticationHeaderBearer.bind(this)()
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
title,
|
||||||
|
content
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
removeArticle(id) {
|
||||||
|
|
||||||
|
return axios({
|
||||||
|
url: '/api/articles/' + id,
|
||||||
|
headers: {
|
||||||
|
'Authorization': commonUtil.getAuthenticationHeaderBearer.bind(this)()
|
||||||
|
},
|
||||||
|
method: 'delete'
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,42 +1,40 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
function login(data) {
|
|
||||||
const { email, password } = data;
|
|
||||||
return axios({
|
|
||||||
method: 'post',
|
|
||||||
url: '/api/auth/login',
|
|
||||||
data: {
|
|
||||||
email,
|
|
||||||
password
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function register(data) {
|
|
||||||
const { email, name, password } = data;
|
|
||||||
return axios({
|
|
||||||
method: 'post',
|
|
||||||
url: '/api/auth/register',
|
|
||||||
data: {
|
|
||||||
email,
|
|
||||||
name,
|
|
||||||
password
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function session(token) {
|
|
||||||
return axios({
|
|
||||||
method: 'get',
|
|
||||||
url: '/api/users',
|
|
||||||
headers: {
|
|
||||||
'Authorization': 'Bearer ' + token
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
login,
|
login(data) {
|
||||||
session,
|
const { email, password } = data;
|
||||||
register
|
return axios({
|
||||||
|
method: 'post',
|
||||||
|
url: '/api/auth/login',
|
||||||
|
data: {
|
||||||
|
email,
|
||||||
|
password
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
session(token) {
|
||||||
|
return axios({
|
||||||
|
method: 'get',
|
||||||
|
url: '/api/users',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + token
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
register(data) {
|
||||||
|
const { email, name, password } = data;
|
||||||
|
return axios({
|
||||||
|
method: 'post',
|
||||||
|
url: '/api/auth/register',
|
||||||
|
data: {
|
||||||
|
email,
|
||||||
|
name,
|
||||||
|
password
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
logout() {
|
||||||
|
this.$cookie.set('accessToken', null, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,5 +8,4 @@ export default async function () {
|
|||||||
'Authorization': 'Bearer ' + this.$cookie.get('accessToken')
|
'Authorization': 'Bearer ' + this.$cookie.get('accessToken')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,24 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
home
|
<router-link to="/auth/login">로그인</router-link> <br>
|
||||||
<router-link to="/auth/login">로그인</router-link>
|
<router-link to="/auth/register">회원가입</router-link> <br>
|
||||||
<router-link to="/auth/register">회원가입</router-link>
|
|
||||||
<router-link to="/articles">게시글</router-link>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import authApi from "../api/authApi";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Welcome"
|
name: "Welcome",
|
||||||
|
async beforeCreate() {
|
||||||
|
const accessToken = this.$cookie.get('accessToken');
|
||||||
|
try {
|
||||||
|
await authApi.session.bind(this)(accessToken);
|
||||||
|
await this.$router.replace('/articles');
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,17 @@
|
|||||||
<div>
|
<div>
|
||||||
<router-link to="/articles/write">글쓰기</router-link>
|
<router-link to="/articles/write">글쓰기</router-link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button type="button" @click="logout">로그아웃</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import articleApi from "../../api/articleApi";
|
import articleApi from "../../api/articleApi";
|
||||||
import authentication from "../../middlewares/authentication";
|
import authentication from "../../middlewares/authentication";
|
||||||
|
import authApi from "../../api/authApi";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "List",
|
name: "List",
|
||||||
@@ -41,6 +46,19 @@
|
|||||||
alert('문제가 발생하였습니다.');
|
alert('문제가 발생하였습니다.');
|
||||||
console.log(err.response);
|
console.log(err.response);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async logout() {
|
||||||
|
if (!confirm('정말 로그아웃 하시겠습니까?')) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await authApi.logout.bind(this)();
|
||||||
|
await this.$router.push('/');
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -23,7 +23,16 @@
|
|||||||
password: ''
|
password: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
async beforeCreate() {
|
||||||
|
const accessToken = this.$cookie.get('accessToken');
|
||||||
|
try {
|
||||||
|
await authApi.session.bind(this)(accessToken);
|
||||||
|
await this.$router.replace('/articles');
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
submit: async function(evt) {
|
submit: async function(evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
const { email, password } = this;
|
const { email, password } = this;
|
||||||
|
|||||||
Reference in New Issue
Block a user