UNPKG

alepha

Version:

Easy-to-use modern TypeScript framework for building many kind of applications.

39 lines (34 loc) 828 B
import { AlephaError } from "alepha"; import type { IssuerPrimitive } from "alepha/security"; import { $auth, type CredentialsFn, type CredentialsOptions, type WithLoginFn, } from "./$auth.ts"; /** * Already configured Credentials authentication primitive. * * Uses username and password to authenticate users. */ export const $authCredentials = ( realm: IssuerPrimitive & WithLoginFn, options: Partial<CredentialsOptions> = {}, ) => { const name = "credentials"; const account: CredentialsFn | undefined = realm.login ? realm.login(name) : options.account; if (!account) { throw new AlephaError( "Credentials authentication requires a login function in the realm primitive.", ); } return $auth({ issuer: realm, name, credentials: { account, }, }); };