Skip to content

PrismaUserStore

The UserStore on a Prisma model.

U extends AuthUser = AuthUser

  • UserStore<U>

new PrismaUserStore<U>(options): PrismaUserStore<U>

PrismaUserStoreOptions<U>

PrismaUserStore<U>

changeEmail(id, change): Promise<EmailChangeResult>

Moves the user to the address to, marks it verified and, with clearPassword, removes the password hash, in one statement, as a compare-and-set on the stored email still equalling from. The address stays unique: of two users changing to one address at once, exactly one gets changed. to may equal from: the revert uses that to remove the password alone when the old address has an account again. Optional, so stores written before it still compile; the email change flows need it and throw AuthConfigError without it.

string

boolean

NormalizedEmail

NormalizedEmail

Promise<EmailChangeResult>

UserStore.changeEmail


create(input): Promise<U | null>

Inserts the user, or answers null when the address (or another unique column) is taken.

Where Prisma accepts createManyAndReturn with skipDuplicates (PostgreSQL and CockroachDB), a taken address is an insert that skips the duplicate and returns no row, not a failed statement. A failed statement makes the driver’s next query on that pool slower (about 3 ms measured on PostgreSQL through @prisma/adapter-pg), and at sign-up that next query would tell a taken address from a new one.

Everywhere else it uses create and reads a unique violation (P2002) as taken: on a delegate without createManyAndReturn (MySQL, SQL Server), and when Prisma refuses the bulk insert with a validation error, which it does on SQLite (no skipDuplicates) and for a createData with nested writes or relation fields (a bulk insert takes plain columns only). That refusal happens in the client, before any statement, and the store remembers it, so later sign-ups go straight to create.

NormalizedEmail

string

Promise<U | null>

UserStore.create


findById(id): Promise<U | null>

string

Promise<U | null>

UserStore.findById


findCredentialByEmail(email): Promise<WithPasswordHash<U> | null>

Live users only: a soft-deleted user is not found. Must match the address exactly, byte for byte: a case- or accent-insensitive lookup (a database collation) would find one row under several spellings. The core also treats a row whose email differs from the address asked for as not found.

NormalizedEmail

Promise<WithPasswordHash<U> | null>

UserStore.findCredentialByEmail


findCredentialById(id): Promise<WithPasswordHash<U> | null>

string

Promise<WithPasswordHash<U> | null>

UserStore.findCredentialById


markEmailVerified(id, email): Promise<boolean>

Guarded on the stored email still equalling email, so a stale link cannot verify a changed address.

string

NormalizedEmail

Promise<boolean>

UserStore.markEmailVerified


setPasswordHash(id, passwordHash, options?): Promise<boolean>

Guarded: false (and nothing written) when the user is missing or soft-deleted. With expected it is a compare-and-set: the write happens only if the stored hash still equals expected (null for no password), in one statement, so a rehash can never overwrite a password changed meanwhile.

string

string

string | null

Promise<boolean>

UserStore.setPasswordHash