
官方 Auth0 动作类型脚本定义, 将帮助您编码并测试您的项目在外部编辑器和IDE上的动作 .
开始
先决条件:
- 节点.js v18 以上
- 类型脚本 5.5 或更高 (促进发展)
- 一个 Auth0 账户
- 基本知识 Auth0 动作
- 一个有 TypeScript 支持的代码编辑器(例如, VS 代码(中文(简体) )
安装 :
使用 npm 安装软件包 :
npm install --save-dev @auth0/actions
或用纱线:
yarn add --dev @auth0/actions
或使用pnpm:
pnpm add --save-dev @auth0/actions
用法 :
使用下列方法之一将类型脚本定义导入您的 Auth0 动作:
@ import:
如果您想要启用 IntelliSense而不改变您现有的 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 注释中的导入语句对类型安全使用此方法:
/**
* 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 开发全类型检查和现代语法时使用此方法 :
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的内部系统自动生成并维护. 需要帮助使用此软件包、报告问题或提供反馈:
- 用法文档: 参见 开始 实例
- Auth0 动作文档数字 : auth0.com/docs/定制/行动
- 支助中心数字 : 支持.auth0.com (中文(简体) )
- 社区论坛数字 : 互联网档案馆的存檔,存档日期2013-10-02.com
许可证
版权2026 Okta, Inc.
这个项目根据Apache 2.0许可证获得许可. 见 自由主义 需要更多信息的文件.
什么是奥特?
Auth0是一个易于执行,可适应的认证和授权平台. 学习更多退房 为什么是Auth0?