typescript 如何使用auth0 API在nestjs中创建用户

plicqrtu  于 2023-03-19  发布在  TypeScript
关注(0)|答案(1)|浏览(123)

我试图用nestjs在auth0 API中创建用户,但给予我错误状态401 enter image description here
我的验证码是:enter code here

@Post()
  async create( @Headers() authorization: string, @Body() User: any) {
    try {
      // @ts-ignore
      const response = await axios.post(process.env.AUTH0_USER_CREATE, authorization, User);
      // tslint:disable-next-line:no-console
      console.log( authorization, User);
      return response;
    } catch (error) {
      // tslint:disable-next-line:no-console
      console.log( error, authorization, User);
      return error;
    }

  }
zvms9eto

zvms9eto1#

根据错误代码,这似乎是身份验证问题。如@Jay McDoniel所述,请确保您以正确的顺序为axios.post提供参数,并且凭据有效。此外,可能值得检查Auth 0日志。
我建议您查看Node Auth0 library以处理这些操作
示例

import { ManagementClient } from 'auth0';

// Authenticating with the Auth0 API
const auth0 = new ManagementClient({
  domain: '{YOUR_ACCOUNT}.auth0.com',
  clientId: '{YOUR_NON_INTERACTIVE_CLIENT_ID}',
  clientSecret: '{YOUR_NON_INTERACTIVE_CLIENT_SECRET}'
});

// Creating a new user
const auth0User = await auth0.createUser(User);

相关问题