Let's combine two Nuxt 2 plugins : nuxt-i18n and @nuxtjs/auth
First we need to create a new @nuxtjs/auth plugin. This is fairly easy !
Let's assume that the user's language preference is indicated in the language property of the user object.
// plugins/auth/locale.js
export default ({ app, $auth }) => {
$auth.onRedirect((to, from) => {
app.i18n.setLocale($auth.user.language)
})
}
Next, register the plugin in
// nuxt.config.js
auth: {
plugins: [
'~/plugins/auth/locale',
],
}