首页 > 解决方案 > 登录时出现 Auth0 和 Nuxt JS 400(无法获取脚本源)错误

问题描述

我对 nuxt 领域很陌生,每次尝试登录时都会遇到 400 页。除了添加 ENV 文件之外,我直接按照Auth/nuxt Docs的指示进行操作。

我还添加了我的应用程序 URI 以允许我的本地主机

这是我的Nuxt.config.js文件,里面包含所有 auth0 配置。

export default {
  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    '@nuxtjs/axios',
    '@nuxtjs/pwa',
    '@nuxtjs/auth-next',
  ],

  axios: {
    baseURL: 'http://localhost:5000',
  },

  env: {
    DOMAIN: process.env.DOMAIN,
    CLIENT_ID: process.env.CLIENT_ID,
    REDIRECT_URI: process.env.REDIRECT_URI,
  },

  // Auth0 Authentication

  auth: {
    redirect: {
      login: '/login', // redirect user when not connected
      logout: '/',
      callback: '/home',
    },
    strategies: {
      auth0: {
        domain: process.env.DOMAIN,
        client_id: process.env.CLIENT_ID,
        audience: 'https://MyApiLinkFromAuth0',
      },
    },
  },
}

这是我在/login页面中的组件。

<template>
  <div>
    Login Page
    <div>
      <button @click="login">Login</button>
    </div>
  </div>
</template>

<script>
export default {
  methods: {
    login() {
      this.$auth.loginWith('auth0')
    },
  },
}
</script>

标签: vue.jsauthenticationnuxt.jsauth0

解决方案


原来它是一个错字client_id。应该是clientId。auth0 日志有所帮助。


推荐阅读