Skip to content

Commit

Permalink
Merge pull request #33 from ckstmznf/master
Browse files Browse the repository at this point in the history
로그인 beforeEnter
  • Loading branch information
kichan05 authored Mar 31, 2022
2 parents ead0e4d + ae9dc1f commit 8e1d39e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import store from "./store.js"
export default {
name: 'App',
name: 'App',
setup() {
},
Expand Down
7 changes: 7 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/components/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</template>
</div>

<span class="k" @click="$router.push('i_love_sunrin')">이스터에그</span>
<!-- <span class="k" @click="$router.push('i_love_sunrin')">이스터에그</span> -->
</nav>
</transition>

Expand Down
16 changes: 15 additions & 1 deletion src/router/router.js
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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",
Expand All @@ -19,7 +27,7 @@ const routes = [
{
path: "/login/token",
name: "token",
component: LoginPage
component: LoginPage,
},
{
path : "/register",
Expand All @@ -30,33 +38,39 @@ 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
},

{
path : "/i_love_sunrin",
name : "easterEgg",
component : EasterEggPage,
beforeEnter: requireAuth(),
}
]

Expand Down

0 comments on commit 8e1d39e

Please sign in to comment.