diff --git a/src/App.vue b/src/App.vue index fd21919..a63e5d5 100644 --- a/src/App.vue +++ b/src/App.vue @@ -10,7 +10,7 @@ import store from "./store.js" export default { - name: 'App', + name: 'App', setup() { }, diff --git a/src/api.js b/src/api.js index 0d4560f..88b07e3 100644 --- a/src/api.js +++ b/src/api.js @@ -20,6 +20,13 @@ export async function getUserData(){ return userData } +export async function logout(){ + store.commit("changeAccessToken", null) + store.commit("setUserData", null) + + return await getAPI.delete("/auth").then(res => res.data).catch(console.log) +} + export async function getScheduleOfficial(){ let schedule = await getAPI.get("/schedule/week").then((res) => res.data).catch((e) => console.log(e)) return schedule diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index 8aeec92..327d145 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -29,7 +29,7 @@ - 이스터에그 + diff --git a/src/router/router.js b/src/router/router.js index 9123f4d..da4c0c0 100644 --- a/src/router/router.js +++ b/src/router/router.js @@ -1,4 +1,5 @@ import { createWebHistory, createRouter } from "vue-router" +import { getUserData } from "./../api.js" import LoginPage from "./../views/LoginPage.vue" import Register from "./../views/RegisterPage.vue" @@ -10,6 +11,13 @@ import NoticeDetailPage from "./../views/NoticeDetailPage.vue" import EasterEggPage from "./../views/EasterEggPage.vue" +const requireAuth = () => (from, to, next) => { + if (getUserData() == null){ + return next('/login') + } + return next() +} + const routes = [ { path : "/login", @@ -19,7 +27,7 @@ const routes = [ { path: "/login/token", name: "token", - component: LoginPage + component: LoginPage, }, { path : "/register", @@ -30,26 +38,31 @@ const routes = [ path : "/", name: "main", component : MainPage, + beforeEnter: requireAuth(), }, { path : "/notice", name: "notice", component : NoticePage, + beforeEnter: requireAuth(), }, { path : "/notice/:noticeId", name: "noticeId", component : NoticeDetailPage, + beforeEnter: requireAuth(), }, { path : "/profile", name: "profile", component : ProfilePage, + beforeEnter: requireAuth(), }, { path : "/club", name: "club", component : ClubPage, + beforeEnter: requireAuth(), props: true }, @@ -57,6 +70,7 @@ const routes = [ path : "/i_love_sunrin", name : "easterEgg", component : EasterEggPage, + beforeEnter: requireAuth(), } ]