简体   繁体   中英

Guest middleware on Nuxt Auth not working

I have a login page that I would like for logged in users not be able to see. My component is as follow:

<template>...</template>
<script lang="ts">
   ...
   @Component({
       layout: 'fullWidth',
       auth: 'guest',
       components: {
         Base,
         BaseAuth,
       }
   })
   export default class Login extends Vue {  ... }
</script>

After login if I go to the /login route it allows me to view the page. My nuxt configuration is as follow:

auth: {
    redirect: {
      login: '/login',
      logout: '/',
      // callback: '/login',
      home: '/'
    },
    strategies: {
      local: {
        endpoints: {
          login: { url: '/auth/login', method: 'post', propertyName: 'token' },
          logout: { url: '/auth/logout', method: 'post' },
          user: { url: '/auth/user', method: 'get', propertyName: 'user' }
        },
      }
    }
  }

Is there any other configuration that I should do?

i know it's not a real solution for the module, but what i end up doing was adding a hook on the login page:

mounted() {
    if (this.$auth.loggedIn) {
    return this.$router.push('/dashboard')
    }
},

use this, first register the middleware then use auth.

 middleware: 'auth', auth: 'guest',

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM