@aimform/auth
v0.3.1
Published
Aimform Auth — authentication (OpenAuth/OAuth2), user profiles, organizations, API tokens, and consent management.
Maintainers
Readme
@aimform/auth
Authentication (OpenAuth/OAuth2), user profiles, organizations, API tokens, and consent management.
Install
npm install @aimform/auth @aimform/coreUsage
import { Auth, Profiles, Orgs, Members, Tokens } from "@aimform/auth";
// D1
const auth = new Auth({ database: env.DB });
const profiles = new Profiles({ database: env.DB });
const members = new Members({ database: env.DB });
// Platform API
const aimform = createAimform({ apiKey: "af_xxx" });
const auth = new Auth({ client: aimform.client });Auth
import { Auth } from "@aimform/auth";
const auth = new Auth({ database: db });
const session = await auth.register("[email protected]", "Jane Doe", "password123");
const session = await auth.login("[email protected]", "password123");
const user = await auth.validateSession(session.token);
await auth.invalidateSession(session.token);
await auth.getUser("user_123");
await auth.forgotPassword("[email protected]");
await auth.resetPassword("token", "newPassword");
await auth.requestMagicLink("[email protected]");Profiles
import { Profiles } from "@aimform/auth";
const profiles = new Profiles({ database: db });
await profiles.get("prof_123");
await profiles.listByUser("user_123");
await profiles.create({ displayName: "Work Profile", profileType: "adult" });
await profiles.update("prof_123", { displayName: "Updated" });
await profiles.delete("prof_123");Orgs
import { Orgs } from "@aimform/auth";
const orgs = new Orgs({ database: db });
await orgs.get("org_456");
await orgs.listByMember("prof_123");
await orgs.create({ name: "My Team", slug: "my-team" });
await orgs.update("org_456", { name: "Renamed" });
await orgs.delete("org_456");Members
import { Members } from "@aimform/auth";
const members = new Members({ database: db });
await members.list("org_456");
await members.invite("org_456", { email: "[email protected]", role: "editor" });
await members.update("org_456", "prof_789", { role: "admin" });
await members.remove("org_456", "prof_789");Tokens
import { Tokens } from "@aimform/auth";
const tokens = new Tokens({ database: db });
const { token } = await tokens.create("prof_123");
await tokens.list("prof_123");
await tokens.revoke("tok_123");