SingleTableIdentifierStore.ts overview
A single-table IdentifierStore: a user’s one email identifier lives on the application’s own users row (email, email_verified, optionally email_verified_at). It is opt-in through layer, and refuses anything but one email with IdentifierRefusedError. The Drizzle guide lists what the table must satisfy.
Example
import { Layer } from "effect"
import * as Drizzle from "@thomasfosterau/effect-auth-drizzle"
// `appUsers` is the application's own table: `email` unique, nullable or
// NOT NULL, with `email_verified_at` mapped if the application keeps one.
const users = Drizzle.SingleTableIdentifierStore.defineUsers({
table: appUsers,
columns: {
id: "userId",
email: "email",
emailVerified: "emailVerified",
emailVerifiedAt: "emailVerifiedAt",
createdAt: "createdAt"
}
})
const identifiers = Drizzle.SingleTableIdentifierStore.layer(users).pipe(
Layer.provide(Drizzle.Database.databaseLayer(db))
)
Exports Grouped by Category
utils
SingleTableUserColumnNames (interface)
Which of TTable’s columns hold each field the single-table store reads and writes.
Signature
export interface SingleTableUserColumnNames<TTable extends Table> {
/** The user's primary key; also the id of the email identifier. */
readonly id: ColumnKey<TTable, string>
/**
* The login address. Unique. Nullable or NOT NULL: the store detects which from
* the column; on a NOT NULL column the store never clears the address.
*/
readonly email: ColumnKey<TTable, string | null>
/** Whether {@link email} has been verified. */
readonly emailVerified: ColumnKey<TTable, boolean>
/**
* When the address was verified, as a nullable timestamp. Optional: when
* mapped, {@link Auth.Identifier.Identifier.verifiedAt} is stored and reported; when not
* mapped it is neither stored nor reported.
*/
readonly emailVerifiedAt?: ColumnKey<TTable, Date | null>
/** The user's creation time, which the email identifier reports as its own. */
readonly createdAt: ColumnKey<TTable, Date>
}
SingleTableUserColumns (type alias)
The resolved column objects the single-table store queries with.
Signature
type SingleTableUserColumns = {
readonly id: StoreColumn<string>
readonly email: NullableColumn<string>
readonly emailVerified: StoreColumn<boolean>
readonly emailVerifiedAt?: NullableColumn<Date>
readonly createdAt: StoreColumn<Date>
}
SingleTableUsers (type alias)
A users table and where the login address lives in it.
emailNullable is read from the drizzle email column by defineUsers: true when the column allows NULL.
Signature
type SingleTableUsers = TableSchema<SingleTableUserColumns> & {
readonly emailNullable: boolean
}
defineUsers
Map an application’s users table onto the single-table store.
Each column is named by its key on the table object, as in defineSchema, not by its database name. The column types are checked at this call site: email must read back as a string or null, emailVerified as a boolean, emailVerifiedAt as a Date or null, createdAt as a Date.
Whether email is nullable is taken from the column’s own NOT NULL setting, so a NOT NULL column is supported without any extra option.
Signature
declare const defineUsers: <TUsers extends Table>(
spec: TableSpec<TUsers, SingleTableUserColumnNames<TUsers>>
) => SingleTableUsers
layer
IdentifierStore over a users table that holds the email itself.
Signature
declare const layer: (users: SingleTableUsers) => Layer.Layer<Auth.Identifier.IdentifierStore, never, DrizzleDatabase>
make
Build a single-table IdentifierStore over the ambient DrizzleDatabase.
Signature
declare const make: (
users: SingleTableUsers
) => Effect.Effect<typeof Auth.Identifier.IdentifierStore.Service, never, DrizzleDatabase>