MongoServicePassword
@accounts/mongo-password › Globals › MongoServicePassword
Hierarchy
- MongoServicePassword
Implements
- DatabaseInterfaceServicePassword
Index
Constructors
Methods
- addEmail
- addEmailVerificationToken
- addResetPasswordToken
- createUser
- findPasswordHash
- findUserByEmail
- findUserByEmailVerificationToken
- findUserById
- findUserByResetPasswordToken
- findUserByUsername
- removeAllResetPasswordTokens
- removeEmail
- setPassword
- setUsername
- setupIndexes
- verifyEmail
Constructors
constructor
+ new MongoServicePassword(options
: MongoServicePasswordOptions): MongoServicePassword
Defined in mongo-password.ts:78
Parameters:
Name | Type |
---|---|
options | MongoServicePasswordOptions |
Returns: MongoServicePassword
Methods
addEmail
▸ addEmail(userId
: string, newEmail
: string, verified
: boolean): Promise‹void›
Defined in mongo-password.ts:245
Add an email address for a user.
Parameters:
Name | Type | Description |
---|---|---|
userId | string | Id used to update the user. |
newEmail | string | A new email address for the user. |
verified | boolean | Whether the new email address should be marked as verified. |
Returns: Promise‹void›
addEmailVerificationToken
▸ addEmailVerificationToken(userId
: string, email
: string, token
: string): Promise‹void›
Defined in mongo-password.ts:361
Add an email verification token to a user.
Parameters:
Name | Type | Description |
---|---|---|
userId | string | Id used to update the user. |
email | string | Which address of the user's to link the token to. |
token | string | Random token used to verify the user email. |
Returns: Promise‹void›
addResetPasswordToken
▸ addResetPasswordToken(userId
: string, email
: string, token
: string, reason
: string): Promise‹void›
Defined in mongo-password.ts:388
Add a reset password token to a user.
Parameters:
Name | Type | Description |
---|---|---|
userId | string | Id used to update the user. |
email | string | Which address of the user's to link the token to. |
token | string | Random token used to verify the user email. |
reason | string | Reason to use for the token. |
Returns: Promise‹void›
createUser
▸ createUser(__namedParameters
: object): Promise‹string›
Defined in mongo-password.ts:126
Create a new user by providing an email and/or a username and password. Emails are saved lowercased.
Parameters:
▪ __namedParameters: object
Name | Type |
---|---|
cleanUser | cleanUser |
email | string |
password | string |
username | string |
Returns: Promise‹string›
findPasswordHash
▸ findPasswordHash(userId
: string): Promise‹string | null›
Defined in mongo-password.ts:206
Return the user password hash. If the user has no password set, will return null.
Parameters:
Name | Type | Description |
---|---|---|
userId | string | Id used to query the user. |
Returns: Promise‹string | null›
findUserByEmail
▸ findUserByEmail(email
: string): Promise‹User | null›
Defined in mongo-password.ts:173
Get a user by one of his emails. Email will be lowercased before running the query.
Parameters:
Name | Type | Description |
---|---|---|
email | string | Email used to query the user. |
Returns: Promise‹User | null›
findUserByEmailVerificationToken
▸ findUserByEmailVerificationToken(token
: string): Promise‹User | null›
Defined in mongo-password.ts:215
Get a user by one of the email verification token.
Parameters:
Name | Type | Description |
---|---|---|
token | string | Verification token used to query the user. |
Returns: Promise‹User | null›
findUserById
▸ findUserById(userId
: string): Promise‹User | null›
Defined in mongo-password.ts:159
Get a user by his id.
Parameters:
Name | Type | Description |
---|---|---|
userId | string | Id used to query the user. |
Returns: Promise‹User | null›
findUserByResetPasswordToken
▸ findUserByResetPasswordToken(token
: string): Promise‹User | null›
Defined in mongo-password.ts:229
Get a user by one of the reset password token.
Parameters:
Name | Type | Description |
---|---|---|
token | string | Reset password token used to query the user. |
Returns: Promise‹User | null›
findUserByUsername
▸ findUserByUsername(username
: string): Promise‹User | null›
Defined in mongo-password.ts:188
Get a user by his username.
Set the caseSensitiveUserName
option to false if you want the username to be case sensitive.
Parameters:
Name | Type |
---|---|
username | string |
Returns: Promise‹User | null›
removeAllResetPasswordTokens
▸ removeAllResetPasswordTokens(userId
: string): Promise‹void›
Defined in mongo-password.ts:414
Remove all the reset password tokens for a user.
Parameters:
Name | Type | Description |
---|---|---|
userId | string | Id used to update the user. |
Returns: Promise‹void›
removeEmail
▸ removeEmail(userId
: string, email
: string): Promise‹void›
Defined in mongo-password.ts:271
Remove an email address for a user.
Parameters:
Name | Type | Description |
---|---|---|
userId | string | Id used to update the user. |
email | string | The email address to remove. |
Returns: Promise‹void›
setPassword
▸ setPassword(userId
: string, newPassword
: string): Promise‹void›
Defined in mongo-password.ts:336
Change the password for a user.
Parameters:
Name | Type | Description |
---|---|---|
userId | string | Id used to update the user. |
newPassword | string | A new password for the user. |
Returns: Promise‹void›
setUsername
▸ setUsername(userId
: string, newUsername
: string): Promise‹void›
Defined in mongo-password.ts:315
Change the username of the user. If the username already exists, the function will fail.
Parameters:
Name | Type | Description |
---|---|---|
userId | string | Id used to update the user. |
newUsername | string | A new username for the user. |
Returns: Promise‹void›
setupIndexes
▸ setupIndexes(options
: Omit‹IndexOptions, "unique" | "sparse"›): Promise‹void›
Defined in mongo-password.ts:95
Setup the mongo indexes needed for the password service.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
options | Omit‹IndexOptions, "unique" | "sparse"› | {} | Options passed to the mongo native createIndex method. |
Returns: Promise‹void›
verifyEmail
▸ verifyEmail(userId
: string, email
: string): Promise‹void›
Defined in mongo-password.ts:292
Marks the user's email address as verified.
Parameters:
Name | Type | Description |
---|---|---|
userId | string | Id used to update the user. |
email | string | The email address to mark as verified. |
Returns: Promise‹void›