Skip to content

Migration Guide

Tony Briet edited this page Jan 30, 2018 · 5 revisions

From 3.x to 4.x

4.x release introduce some new features but also includes breaking changes, this guide will allow you to easily upgrade from 3.x to 4.x

Behavioural changes

  • The module now watches any changes from auth/loggedIn getter and automatically redirects users on login and logout.

NOTE : User will be redirected using notLoggedIn and loggedIn from redirect options

Migration example

If you were using promise acceptance to redirect users after login and logout like this:

// Login example
store.dispatch('auth/login', {
  fields: {
    username: 'your_username',
    password: 'your_password'
  }
}).then(() => this.$router.replace('/'))

// Logout example
store.dispatch('auth/logout').then(() => this.$router.replace('/login'))

You can now remove this.$router.replace from your promise acceptance.

Middleware changes

  • auth middleware now manages both authenticated and unauthenticated user redirection
  • no-auth middleware have been removed and merged into auth middleware
  • In order to manage auth middleware redirection behaviour, new options have been added to redirect configuration:
    • guest (Boolean) - Enable or disable unauthenticated middleware redirection. (default: true)
    • user (Boolean) - Enable or disable authenticated middleware redirection. (default: true)

Migration example

Authenticated and unauthenticated redirection

If you were using the following configuration in 3.x :

// nuxt.config.js
router: {
  middleware: [
    'auth',
    'no-auth'
  ]
}

This is the corresponding configuration in 4.x :

// nuxt.config.js
router: {
  middleware: [
    'auth',
  ]
}

Unauthenticated redirection only

If you were using the following configuration in 3.x :

// nuxt.config.js
router: {
  middleware: [
    'auth',
  ]
}

This is the corresponding configuration in 4.x :

// nuxt.config.js
auth: {
  redirect: {
    user: false
  }
},
router: {
  middleware: [
    'auth',
  ]
}

Authenticated redirection only

If you were using the following configuration in 3.x :

router: {
  middleware: [
    'no-auth',
  ]
}

This is the corresponding configuration in 4.x :

// nuxt.config.js
auth: {
  redirect: {
    guest: false
  }
},
router: {
  middleware: [
    'auth',
  ]
}

Clone this wiki locally