UNPKG

@softr/sdk

Version:

The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.

80 lines (78 loc) • 2.95 kB
import { User } from "../user.js"; import { AuthError, Result } from "./utils.js"; //#region src/auth/methods/authenticator.d.ts /** * Starts enrolling an authenticator app, for a sign-in that asked to set one up * or for a signed-in visitor adding one. * * `otpauthUri` is what an authenticator app reads. `qrPngBase64` is that same * URI as a PNG for `<img src="data:image/png;base64,…">`, so a page can show * the QR code without a QR library. Neither one enrols anybody. * {@link confirmAuthenticatorSetup} does that, once it accepts a first code. * * Call it again to hand back a fresh QR code, for a visitor who lost the first * one. Only the newest one enrols them. */ declare function startAuthenticatorSetup(): Promise<Result<{ otpauthUri: string; qrPngBase64: string; }, AuthError>>; /** * Enrols the authenticator app on its first code and signs the visitor in. * * This is the only call that returns the backup codes, and it returns them * once. Nothing fetches them again, so render them before leaving the page. */ declare function confirmAuthenticatorSetup(details: { code: string; }): Promise<Result<{ user: User; backupCodes: Array<string>; }, AuthError>>; /** * Skips enrolment and finishes the sign-in, for a visitor whose app offers an * authenticator without requiring one. Only the `setupOptional` step. * * Later sign-ins stop asking. */ declare function skipAuthenticatorSetup(): Promise<Result<User, AuthError>>; /** * Finishes a sign-in that stopped at the `verify` step, with the code the * visitor's authenticator app shows or one of their backup codes. * * Each backup code works once. */ declare function verifyAuthenticator(credentials: { code: string; } | { backupCode: string; }): Promise<Result<User, AuthError>>; /** * Emails the signed-in visitor the code that {@link resetAuthenticator} and * {@link removeAuthenticator} ask for. * * Both change how the visitor signs in, so both want a code from their inbox * on top of being signed in. */ declare function sendAuthenticatorResetCode(): Promise<Result<null, AuthError>>; /** * Unpairs the visitor's authenticator app so they can enrol a new one with * {@link startAuthenticatorSetup}, after a lost or replaced phone. * * `code` is the one {@link sendAuthenticatorResetCode} emailed. */ declare function resetAuthenticator(details: { code: string; }): Promise<Result<null, AuthError>>; /** * Turns the visitor's authenticator app off entirely. * * `code` is the one {@link sendAuthenticatorResetCode} emailed. An app that * requires an authenticator will ask them to set one up again on their next * sign-in. */ declare function removeAuthenticator(details: { code: string; }): Promise<Result<null, AuthError>>; //#endregion export { confirmAuthenticatorSetup, removeAuthenticator, resetAuthenticator, sendAuthenticatorResetCode, skipAuthenticatorSetup, startAuthenticatorSetup, verifyAuthenticator };