PrismaUserStore
The UserStore on a Prisma model.
Type Parameters
Section titled “Type Parameters”U extends AuthUser = AuthUser
Implements
Section titled “Implements”UserStore<U>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new PrismaUserStore<
U>(options):PrismaUserStore<U>
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”PrismaUserStore<U>
Methods
Section titled “Methods”changeEmail()
Section titled “changeEmail()”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.
Parameters
Section titled “Parameters”string
change
Section titled “change”clearPassword?
Section titled “clearPassword?”boolean
NormalizedEmail
NormalizedEmail
Returns
Section titled “Returns”Promise<EmailChangeResult>
Implementation of
Section titled “Implementation of”UserStore.changeEmail
create()
Section titled “create()”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.
Parameters
Section titled “Parameters”NormalizedEmail
passwordHash
Section titled “passwordHash”string
Returns
Section titled “Returns”Promise<U | null>
Implementation of
Section titled “Implementation of”UserStore.create
findById()
Section titled “findById()”findById(
id):Promise<U|null>
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<U | null>
Implementation of
Section titled “Implementation of”UserStore.findById
findCredentialByEmail()
Section titled “findCredentialByEmail()”findCredentialByEmail(
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.
Parameters
Section titled “Parameters”NormalizedEmail
Returns
Section titled “Returns”Promise<WithPasswordHash<U> | null>
Implementation of
Section titled “Implementation of”UserStore.findCredentialByEmail
findCredentialById()
Section titled “findCredentialById()”findCredentialById(
id):Promise<WithPasswordHash<U> |null>
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<WithPasswordHash<U> | null>
Implementation of
Section titled “Implementation of”UserStore.findCredentialById
markEmailVerified()
Section titled “markEmailVerified()”markEmailVerified(
id,Promise<boolean>
Guarded on the stored email still equalling email, so a stale link cannot verify a changed address.
Parameters
Section titled “Parameters”string
NormalizedEmail
Returns
Section titled “Returns”Promise<boolean>
Implementation of
Section titled “Implementation of”UserStore.markEmailVerified
setPasswordHash()
Section titled “setPasswordHash()”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.
Parameters
Section titled “Parameters”string
passwordHash
Section titled “passwordHash”string
options?
Section titled “options?”expected?
Section titled “expected?”string | null
Returns
Section titled “Returns”Promise<boolean>
Implementation of
Section titled “Implementation of”UserStore.setPasswordHash