【问题标题】:how create user in nestjs using auth0 api如何使用 auth0 api 在 nestjs 中创建用户
【发布时间】:2022-10-04 18:21:32
【问题描述】:

我尝试使用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;
    }

  }
  • axios的签名不是post(url, body, options)吗?所以你需要做axios.post(process.env.AUTH0_USER_CREATE, User, { headers: { authorization: authroization.authorization } })
  • 请将错误响应格式化为代码块而不是图像。

标签: typescript nestjs auth0


【解决方案1】:

根据错误代码,它似乎是身份验证问题。正如@Jay McDoniel 所说,确保您以正确的顺序向axios.post 提供参数并且凭据有效。此外,检查Auth0 logs 可能是值得的。

我建议您查看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);

【讨论】:

    猜你喜欢
    • 2021-10-09
    • 2019-11-08
    • 2019-05-08
    • 2021-10-02
    • 2020-12-14
    • 2017-06-06
    • 2021-10-26
    • 2022-08-23
    • 2019-08-11
    相关资源
    最近更新 更多