# @auth0/actions 中文文档

规范地址：https://npmcn.com/package/%40auth0/actions/

版本：0\.36\.0
npm 元数据更新时间：2026-10-30T17:39:40.476Z
中文译文更新时间：2026-11-07T05:45:33.403Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40auth0/actions
原文对照：https://npmcn.com/package/%40auth0/actions/?lang=original
项目主页：https://auth0.com/docs/customize/actions/actions-npm
源码仓库：https://github.com/auth0/auth0-actions

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：661 kB，52 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=18\.0\.0
- 运行依赖：0 个
- 首次发布：2025-10-21T15:10:59.713Z
- 最新版本发布：2026-10-30T17:39:40.110Z
- 近 30 天下载量：214684（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：31（近 12 个月 27 个）

## 中文简介

Auth0 Official Actions TypeScript定义,该定义将帮助您编码并测试您的项目在外部编辑器和IDE上的动作.

## 安装

```sh
npm install @auth0/actions
```

也可以使用：`pnpm add @auth0/actions`、`yarn add @auth0/actions`、`bun add @auth0/actions`

## README

![Actions for Auth0](https://cdn.auth0.com/website/auth0-actions/banner.png)

[![License](https://img.shields.io/:license-Apache2.0-blue.svg?style=flat)](https://opensource.org/licenses/Apache-2.0) [![NPM Downloads](https://img.shields.io/npm/dw/%40auth0%2Factions)](https://www.npmjs.com/package/@auth0/actions)

🚀 [开始](https://npmcn.com/package/%40auth0/actions/#readme--getting-started) • [反馈](https://npmcn.com/package/%40auth0/actions/#readme--feedback-and-contributing)

官方 Auth0 动作类型脚本定义, 将帮助您编码并测试您的项目在外部编辑器和IDE上的动作 .

## 开始

**先决条件:**

-   [节点.js v18 以上](https://nodejs.org/en/download)
-   [类型脚本 5.5 或更高](https://www.typescriptlang.org/download) (促进发展)
-   一个 [Auth0 账户](https://auth0.com/signup)
-   基本知识 [Auth0 动作](https://auth0.com/docs/customize/actions)
-   一个有 TypeScript 支持的代码编辑器(例如, [VS 代码](https://code.visualstudio.com/)(中文(简体) )

**安装 :**

使用 npm 安装软件包 :

```bash
npm install --save-dev @auth0/actions
```

或用纱线:

```bash
yarn add --dev @auth0/actions
```

或使用pnpm:

```bash
pnpm add --save-dev @auth0/actions
```

**用法 :**

使用下列方法之一将类型脚本定义导入您的 Auth0 动作:

**@ import:**

如果您想要启用 IntelliSense而不改变您现有的 JavaScript 代码结构, 请使用此方法 :

```javascript
/** @import {Event, PostLoginAPI} from "@auth0/actions/post-login/v3" */

/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
  const user = event.user;

  // Your Action logic here
  if (user.email?.endsWith('@example.com')) {
    api.user.setAppMetadata('department', 'internal');
  }
}
```

**校对:Soup**

JavaScript 文件中使用 JSDoc 注释中的导入语句对类型安全使用此方法:

```javascript

/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {import('@auth0/actions/post-login/v3').Event} event - Details about the user and the context in which they are logging in.
* @param {import('@auth0/actions/post-login/v3').PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
  const user = event.user;

  // Your Action logic here
  if (user.email?.endsWith('@example.com')) {
    api.user.setAppMetadata('department', 'internal');
  }
}
```

**类型脚本导入 :**

在使用 TypeScript 开发全类型检查和现代语法时使用此方法 :

```typescript
import type { Event, PostLoginAPI } from '@auth0/actions/post-login/v3';

/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event: Event, api: PostLoginAPI) => {
  const user = event.user;

  // Your Action logic here
  if (user.email?.endsWith('@example.com')) {
    api.user.setAppMetadata('department', 'internal');
  }
};
```

> **重要内容:** 使用 TypeScript 时,必须在部署到 Auth0 之前将您的代码编译为 JavaScript 。 Auth0 动作运行时间只执行 JavaScript 。 使用 TypeScript 编译器(`tsc`转写您的 `.ts` 文件为 `.js` 文档,在可以部署之前。 您还必须加入 JSDoc 评论, 以启用 Intellisense 在 Dashboard 中.

## 反馈和贡献

此寄存器包含自动生成的类型Script类型和用于Auth0动作开发的公用设备. 本套件中的类型由Auth0的内部系统生成并被发布,以帮助开发者构建Action. **该寄存器不接受外部捐款.** 此包的内容由Auth0的内部系统自动生成并维护. 需要帮助使用此软件包、报告问题或提供反馈:

-   **用法文档**: 参见 [开始](https://npmcn.com/package/%40auth0/actions/#readme--getting-started) 实例
-   **Auth0 动作文档**数字 : [auth0.com/docs/定制/行动](https://auth0.com/docs/customize/actions)
-   **支助中心**数字 : [支持.auth0.com (中文(简体) )](https://support.auth0.com/)
-   **社区论坛**数字 : [互联网档案馆的存檔,存档日期2013-10-02.com](https://community.auth0.com/)

## 许可证

版权2026 Okta, Inc.

这个项目根据Apache 2.0许可证获得许可. 见 [自由主义](https://cdn.auth0.com/website/auth0-actions/LICENSE.txt) 需要更多信息的文件.

## 什么是奥特?

![Auth0 Logo](https://cdn.auth0.com/website/sdks/logos/auth0_light_mode.png)

Auth0是一个易于执行,可适应的认证和授权平台. 学习更多退房 [为什么是Auth0?](https://auth0.com/why-auth0)

## 常见问题

### @auth0/actions 是什么？

Auth0 Official Actions TypeScript定义,该定义将帮助您编码并测试您的项目在外部编辑器和IDE上的动作\.

### 如何安装 @auth0/actions？

在项目目录运行 npm install @auth0/actions，或使用 pnpm add / yarn add / bun add。

### @auth0/actions 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @auth0/actions 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @auth0/actions 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=18\.0\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @auth0/actions 可以商用吗？

@auth0/actions 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @auth0/actions 的下载量有多少？

根据 npm 官方下载统计，@auth0/actions 在 2026/10/07 – 2026/11/05 这 30 天内被下载 214,684 次，日均约 7,156 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @auth0/actions 还在维护吗？

最新版本 0\.36\.0 发布于 2026/10/31（8 天前）；至今共发布 31 个版本，其中过去 12 个月发布了 27 个；首次发布于 2025/10/21。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

