Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 仅使用令牌在nuxtjs中自动登录_Javascript_Nuxtjs - Fatal编程技术网

Javascript 仅使用令牌在nuxtjs中自动登录

Javascript 仅使用令牌在nuxtjs中自动登录,javascript,nuxtjs,Javascript,Nuxtjs,我有一个移动应用程序,使用laravel passport作为身份验证手段(这里没有问题)。在移动应用程序中,我添加了一个按钮,理论上会将我重定向到我的web应用程序(与移动应用程序相同的身份验证端点),并自动让我登录。如何使用nuxtjs(已经使用nuxt auth)实现这一点?无法找到仅使用nuxt auth中的令牌登录的方法,或对其进行破解 如果您有任何建议或建议,请随时添加 我想象这样的事情,但没有运气 this.$auth.loginWith('local',

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

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

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

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


我和你有一个类似的问题,但我没有使用laravel passport,而是使用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()
            })
          })
    })
    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()
            })
          })
    })