@afterauth/sdk
v0.1.2
Published
Post-auth controls for costly AI, API, and trial usage
Readme
@afterauth/sdk
Post-auth controls for costly AI, API, and trial usage.
AfterAuth lets you keep signup open while deciding what each user gets next: allow, limit, delay, verify, or deny protected product actions.
Install
npm install @afterauth/sdkQuick Start
Create a client with a workspace API key, then evaluate a protected action before running the costly product work.
import { AfterAuthClient } from "@afterauth/sdk";
const afterauth = new AfterAuthClient({
apiKey: process.env.AFTERAUTH_API_KEY!,
});
const decision = await afterauth.evaluateAction({
action: "ai_generation",
userId: "user_123",
requestedAmount: 1,
signals: {
email: "[email protected]",
emailVerified: true,
accountAgeDays: 3,
hasPaymentMethod: false,
},
metadata: {
surface: "studio",
},
});
if (decision.outcome === "deny") {
throw new Error("Action denied by AfterAuth");
}
if (decision.outcome === "require_verification") {
// Ask the user for the verification step your product already supports.
}
// Run the protected product action, respecting decision.approvedAmount
// and decision.allowedCapabilities when your policy returns limits.Report Completions
After the protected action completes, report the event so future decisions can use the user's activity history.
await afterauth.reportCompletion({
action: "ai_generation",
userId: "user_123",
decisionId: decision.id,
requestId: decision.requestId,
metadata: {
unitsUsed: 1,
},
});Why AfterAuth
- Keep signup open without giving every new account an open tab.
- Protect expensive product moments after login.
- Return explicit decisions for protected actions.
- Keep receipts for every decision.
Links
- Website: https://afterauth.com
- Core engine: https://www.npmjs.com/package/@afterauth/core
