Skip to content

Nuxt Auth redirects home not working #1351

@alimuradov

Description

@alimuradov

Version

V5
nuxt.config.js

//Nuxt Auth module configuration https://auth.nuxtjs.org/schemes/local
auth: {
  // rewriteRedirects: true,
  // watchLoggedIn: true,
  cookie: {
    options: {
        maxAge: 60 * 60 * 60 // 60 hours
    }
  },
  localStorage: {
    prefix: 'auth.'
  },
  strategies: {
    local: {
      token: {
        prefix: 'access_token.',
        property: 'access_token',
        type: 'Bearer',
        maxAge: 60 * 60 * 60
      },
      user: {
        property: 'user',
        autoFetch: true
      },
      endpoints: {
        login: { url: '/api/v1/login/access-token', method: 'post' },
        logout: false,
        user: { url: '/api/v1/users/me', method: 'get' }
      },
      redirect: {
        login: '/login',
        logout: false,
        // callback: '/login',
        home: '/dashboard'
        }
      }
    }
  },  

Login.vue

export default {
  auth: 'guest',
  // middleware: 'authenticated',
  data () {
    return {
      username: 'tabarigen@mail.ru',
      password: '5vn63ys9'
    }
  },
  methods: {
    async authenticate () {
      const form = new FormData()
      form.append('username', this.username)
      form.append('password', this.password)
      await this.$auth.loginWith('local', { data: form })
        .then(() => {
          // this.$router.push({ path: 'dashboard' })
        })
        .catch((err) => {
          console.log(err.res)
        })
    }
  }
}

Very strange module behavior. Sometimes it works, sometimes it doesn't.
Please help me figure it out. I need the user to be redirected to the dashboard page after authorization

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions