Convert.ts overview

BetterAuth rows as effect-auth domain values, and BetterAuth’s APIError as effect-auth’s typed errors.

Since v0.1.0


Exports Grouped by Category


conversions

identifierId

The deterministic id of a derived identifier.

Signature

declare const identifierId: (userId: string, type: Auth.Identifier.IdentifierType) => string

Source

Since v0.1.0

identifiersOf

The identifiers a BetterAuth user holds, each with a deterministic id (${userId}:email, :username, :phone): the email, the username() plugin’s username and the phoneNumber() plugin’s number.

Signature

declare const identifiersOf: (user: BetterAuthUser) => ReadonlyArray<Auth.Identifier.Identifier>

Source

Since v0.1.0

rolesOf

Roles from the admin plugin’s role column, which holds several roles comma-separated ("admin,user").

Signature

declare const rolesOf: (user: Auth.Types.User) => ReadonlyArray<string>

Source

Since v0.1.0

toSession

A BetterAuth session as a Types.Session, named by its stored id. lastActivityAt is BetterAuth’s updatedAt.

Signature

declare const toSession: (session: BetterAuthSession) => Auth.Types.Session

Source

Since v0.1.0

toUser

A BetterAuth user as a Types.User. email, username and phoneNumber stay off it, as in the core, and are reached through the derived identifiers.

Signature

declare const toUser: (user: BetterAuthUser) => Auth.Types.User

Source

Since v0.1.0

errors

CredentialError (type alias)

What an APIError from BetterAuth’s server API becomes.

Signature

type CredentialError =
  | Auth.Errors.AuthError
  | Auth.Errors.InvalidCredentialsError
  | Auth.Errors.EmailInUseError
  | Auth.Errors.EmailNotVerifiedError

Source

Since v0.1.0

fromApiError

Map a rejection from auth.api.* by status and body.code. Anything else, including a thrown non-APIError, is AuthError with the cause kept; a 429 keeps BetterAuth’s error (and its X-Retry-After) as the cause.

Signature

declare const fromApiError: (error: unknown, email?: string) => CredentialError

Source

Since v0.1.0


This site uses Just the Docs, a documentation theme for Jekyll.