0

我有一个使用 laravel 护照作为身份验证手段的移动应用程序(这里没问题)。在移动应用程序中,我添加了一个按钮,理论上将我重定向到我的网络应用程序(与移动设备相同的身份验证端点)并自动登录。如何使用 nuxtjs(已使用 nuxt 身份验证)实现这一点?找不到仅使用 nuxt auth 中的令牌登录或破解它的方法。

如果您有任何建议或建议,请随时添加。

我想象这样的事情,但没有运气。

            this.$auth.loginWith('local', {
                data: {
                    token: token <--------------------------- token from url (originated in mobile app)
                }
            })
            .then(response => {
                // successful login
            })
            .catch(error => {
                // failed login
            });

这是我想在 nuxtjs 中自动登录的示例 url

http://example.com/redirect?token=tokenvaluehere
4

1 回答 1

0

我和你有类似的问题,但是我没有使用 laravel 护照,而是使用 jwt-auth 和本地策略。我使用下面的代码实现了自动登录功能。也许它有帮助:

    const route = ''; // Route from where to get the Token
    this.$auth.reset().then(() => {
      this.$axios.get(route)
          .then(({data}) => {
            this.$auth.setStrategy('local').then(() => {

              const token = this.$auth.strategy.options.tokenType
                  ? this.$auth.strategy.options.tokenType + ' ' + data.login_token
                  : data.login_token

              this.$auth.setToken('local', token)
              this.$auth.strategy._setToken(token)
              this.$auth.fetchUser()
            })
          })
    })
于 2020-12-20T00:43:03.193 回答