Browse Source

페이지별 권한 적용 (미들웨어적용)

yongun 5 years ago
parent
commit
c7c5dddc05
3 changed files with 13 additions and 1 deletions
  1. 5 0
      middleware/auth.js
  2. 6 0
      pages/login/index.vue
  3. 2 1
      pages/register/index.vue

+ 5 - 0
middleware/auth.js

@@ -0,0 +1,5 @@
+export default function ({ store }, redirect) {
+  if (store.getters.isAuthenticated) {
+    return redirect('/')
+  }
+}

+ 6 - 0
pages/login/index.vue

@@ -1,3 +1,9 @@
 <template>
   <p>login</p>
 </template>
+
+<script>
+export default {
+  middleware: 'auth'
+}
+</script>

+ 2 - 1
pages/register/index.vue

@@ -52,6 +52,7 @@
 
 <script>
 export default {
+  middleware: 'auth',
   data: () => ({
     form: {
       email: '',
@@ -69,7 +70,7 @@ export default {
   watch: {
     isAuthenticated (value) {
       if (value) {
-        setTimeout(() => this.$router.push('/'), 2000)
+        setTimeout(() => this.$router.push('/'), 500)
       }
     }
   },