diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index e154a6e..e41179d 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -42,12 +42,15 @@ router.beforeEach((to, from, next) => { return; } - if (to.path !== '/login' && !sessionStorage.getItem('rttys-sid')) { - router.push('/login'); - return; + if (to.path !== '/login') { + Vue.axios.get('/alive').then(() => { + next(); + }).catch(() => { + router.push('/login'); + }); + } else { + next(); } - - next(); }); export default router diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue index 99d99bf..cf4b8f7 100644 --- a/frontend/src/views/Home.vue +++ b/frontend/src/views/Home.vue @@ -221,7 +221,9 @@ handleUserCommand(command: string) { if (command === 'logout') { - this.$router.push('/login'); + this.axios.get('/signout').then(() => { + this.$router.push('/login'); + }); } } diff --git a/frontend/vue.config.js b/frontend/vue.config.js index 14a4622..6f4d311 100644 --- a/frontend/vue.config.js +++ b/frontend/vue.config.js @@ -21,6 +21,12 @@ module.exports = { '/signin': { target: 'http://127.0.0.1:5913' }, + '/signout': { + target: 'http://127.0.0.1:5913' + }, + '/alive': { + target: 'http://127.0.0.1:5913' + }, '/signup': { target: 'http://127.0.0.1:5913' }, diff --git a/http.go b/http.go index 06f9c87..5a83fbc 100644 --- a/http.go +++ b/http.go @@ -203,6 +203,25 @@ func httpStart(br *broker) { c.Status(http.StatusForbidden) }) + r.GET("/alive", func(c *gin.Context) { + if !httpAuth(c) { + c.AbortWithStatus(http.StatusUnauthorized) + } else { + c.Status(http.StatusOK) + } + }) + + r.GET("/signout", func(c *gin.Context) { + cookie, err := c.Cookie("sid") + if err != nil || !httpSessions.Have(cookie) { + return + } + + httpSessions.Del(cookie) + + c.Status(http.StatusOK) + }) + r.POST("/signup", func(c *gin.Context) { var creds credentials