Skip to main content

Function: createEmailAuthHandlers()

createEmailAuthHandlers(options): EmailAuthHandlers

Defined in: emailAuth.ts:42

Runner-agnostic engine for the email and password credential flows — password sign-up and sign-in, magic links, mailed numeric codes, address confirmation and password reset.

It owns the security mechanics and nothing else: persistence arrives as stores, session minting as issueSession, and mail delivery as sendEmail, so the package carries no database and no mail-transport dependency. Mount it with an adapter — emailAuth() from @ttoss/http-server-auth for Koa.

modes decides which handlers exist, so an application that only signs users in with a mailed code never exposes a password endpoint. A configuration that cannot be served safely throws here, at startup, rather than on a request.

Parameters

ParameterType
optionsEmailAuthOptions

Returns

EmailAuthHandlers

Example

const handlers = createEmailAuthHandlers({
modes: ['emailCode'],
userStore,
oneTimeTokenStore,
issueSession: (user) => issueSession(user),
sendEmail: async ({ to, token }) => ses.send(buildCodeEmail(to, token)),
});