首页 > 解决方案 > 未登录时 Nuxt auth 重定向不起作用

问题描述

我正在使用 Nuxt 和 Auth 模块。我试图在用户未登录时将其重定向到登录页面。

nuxt.config.js:

auth: {
  redirect: {
    login: '/account/inloggen',
    logout: '/account/uitloggen',
    callback: '/account/aanmelden',
    home: '/'
  },
  strategies: {
    google: {
      access_token_endpoint: '****/social?identityProvider=Google',
      access_type: 'offline',
      client_id: '*****.apps.googleusercontent.com',
      grant_type: 'authorization_code',
      redirect_uri: 'http://localhost:3000/account/aanmelden',
      response_type: 'code',
      token_key: 'jwt',
      userinfo_endpoint: '****/user/profile'
    }
  },
  cookie: {
    options: {
      maxAge: 86400
    }
  }
  // localStorage: false
},

我正在阅读文档

login:如果需要登录,用户将被重定向到此路径。

但我找不到要求用户登录的位置/方式。

重定向确实有效,当home: '/'用户登录时,他们被重定向到应用程序的根目录。

标签: vuejs2nuxt.js

解决方案


在Github上找到我的答案

我也遇到过这个问题。我的错误是在我的登录页面上设置了 auth: false 。如果你有它,只需将其删除。

<script>
export default {
  auth: false
}
</script>

推荐阅读