import { Auth0AI } from "@auth0/ai-langchain";
// Create Auth0AI client
const auth0AI = new Auth0AI();
// Define async user confirmation flow for buying stocks
const buyStockAuthorizer = auth0AI.withAsyncUserConfirmation({
// Identify the user
userID: (params: { userID: string }, ctx) => params.userID,
// Message shown to user for confirmation
bindingMessage: async ({ qty, ticker }) =>
`Confirm the purchase of ${qty} ${ticker}`,
// Details of the authorization request
authorizationDetails: async ({ qty, ticker }) => [
{ type: "trade_authorization", qty, ticker, action: "buy" }
],
// Target API and required scopes
audience: process.env["AUDIENCE"],
scopes: ["stock:trade"]
});