Users.ts overview

Users and identifiers over BetterAuth’s user table: the core’s UserStore, UserServiceStore, AccountDeletion and a read-only IdentifierStore.

Since v0.1.0


Exports Grouped by Category


layers

accountDeletionLayer

The core’s AccountDeletion over BetterAuth, which UserService.deleteUser delegates to: the user’s sessions, then the user and its account rows. It skips /delete-user’s fresh-session and verification checks, so it is for trusted server code. Rows BetterAuth’s plugins keep elsewhere (organization members, two-factor, passkeys) go only as far as BetterAuth’s own deleteUser takes them.

Signature

declare const accountDeletionLayer: Layer.Layer<Auth.AccountDeletion.AccountDeletion, never, BetterAuthInstance>

Source

Since v0.1.0

identifierStoreLayer

A read-only IdentifierStore. Identifiers are derived from the user row (email and emailVerified; username from the username() plugin; phoneNumber and phoneNumberVerified from the phoneNumber() plugin), each with the id ${userId}:${type}.

Writes that would skip BetterAuth’s checks are refused: create fails with IdentifierRefusedError, and replace, delete and deleteByUser with AuthError, because an email change that skips verification is an account-takeover vector. setVerified marks the email (or phone) verified.

Signature

declare const identifierStoreLayer: Layer.Layer<Auth.Identifier.IdentifierStore, never, BetterAuthInstance>

Source

Since v0.1.0

userServiceStoreLayer

The core’s UserServiceStore over BetterAuth, so Auth.User.UserService.layer() runs on top: update writes only the fields that changed, and only columns BetterAuth declares; delete removes the user’s sessions, then the user (BetterAuth deletes its account rows with it).

Signature

declare const userServiceStoreLayer: Layer.Layer<Auth.User.UserServiceStore, never, BetterAuthInstance>

Source

Since v0.1.0

userStoreLayer

The core’s UserStore over internalAdapter.findUserById.

Signature

declare const userStoreLayer: Layer.Layer<Auth.UserStore.UserStore, never, BetterAuthInstance>

Source

Since v0.1.0

usersLayer

Every layer in this file, plus Auth.User.UserService on top, over one BetterAuth instance.

Signature

declare const usersLayer: (config?: {
  readonly serverOnlyAttributes?: ReadonlyArray<string>
}) => Layer.Layer<
  | Auth.User.UserService
  | Auth.UserStore.UserStore
  | Auth.User.UserServiceStore
  | Auth.AccountDeletion.AccountDeletion
  | Auth.Identifier.IdentifierStore,
  never,
  BetterAuthInstance
>

Source

Since v0.1.0


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