UserService
UserService
Contains methods relating to User entities.
Signature
class UserService {
constructor(connection: TransactionalConnection, configService: ConfigService, roleService: RoleService, passwordCipher: PasswordCipher, verificationTokenGenerator: VerificationTokenGenerator)
async getUserById(ctx: RequestContext, userId: ID) => Promise<User | undefined>;
async getUserByEmailAddress(ctx: RequestContext, emailAddress: string, userType?: 'administrator' | 'customer') => Promise<User | undefined>;
async createCustomerUser(ctx: RequestContext, identifier: string, password?: string) => Promise<User | PasswordValidationError>;
async addNativeAuthenticationMethod(ctx: RequestContext, user: User, identifier: string, password?: string) => Promise<User | PasswordValidationError>;
async createAdminUser(ctx: RequestContext, identifier: string, password: string) => Promise<User>;
async softDelete(ctx: RequestContext, userId: ID) => ;
async setVerificationToken(ctx: RequestContext, user: User) => Promise<User>;
async verifyUserByToken(ctx: RequestContext, verificationToken: string, password?: string) => Promise<ErrorResultUnion<VerifyCustomerAccountResult, User>>;
async setPasswordResetToken(ctx: RequestContext, emailAddress: string) => Promise<User | undefined>;
async resetPasswordByToken(ctx: RequestContext, passwordResetToken: string, password: string) => Promise<
User | PasswordResetTokenExpiredError | PasswordResetTokenInvalidError | PasswordValidationError
>;
async changeNativeIdentifier(ctx: RequestContext, userId: ID, newIdentifier: string) => ;
async setIdentifierChangeToken(ctx: RequestContext, user: User) => Promise<User>;
async changeIdentifierByToken(ctx: RequestContext, token: string) => Promise<
| { user: User; oldIdentifier: string }
| IdentifierChangeTokenInvalidError
| IdentifierChangeTokenExpiredError
>;
async updatePassword(ctx: RequestContext, userId: ID, currentPassword: string, newPassword: string) => Promise<boolean | InvalidCredentialsError | PasswordValidationError>;
}
Members
constructor
(connection: TransactionalConnection, configService: ConfigService, roleService: RoleService, passwordCipher: PasswordCipher, verificationTokenGenerator: VerificationTokenGenerator) => UserService
getUserById
(ctx: RequestContext, userId: ID) => Promise<User | undefined>
getUserByEmailAddress
(ctx: RequestContext, emailAddress: string, userType?: 'administrator' | 'customer') => Promise<User | undefined>
createCustomerUser
(ctx: RequestContext, identifier: string, password?: string) => Promise<User | PasswordValidationError>
customer
Role and using the NativeAuthenticationStrategy.
addNativeAuthenticationMethod
(ctx: RequestContext, user: User, identifier: string, password?: string) => Promise<User | PasswordValidationError>
requireVerification
is set to true
(as is the default), the User will be marked as unverified until the email verification
flow is completed.
createAdminUser
(ctx: RequestContext, identifier: string, password: string) => Promise<User>
softDelete
(ctx: RequestContext, userId: ID) =>
setVerificationToken
(ctx: RequestContext, user: User) => Promise<User>
verificationToken
as part of the User email verification
flow.
verifyUserByToken
(ctx: RequestContext, verificationToken: string, password?: string) => Promise<ErrorResultUnion<VerifyCustomerAccountResult, User>>
Verifies a verificationToken by looking for a User which has previously had it set using the
setVerificationToken()
method, and checks that the token is valid and has not expired.
If valid, the User will be set to verified: true
.
setPasswordResetToken
(ctx: RequestContext, emailAddress: string) => Promise<User | undefined>
passwordResetToken
as part of the User password reset
flow.
resetPasswordByToken
(ctx: RequestContext, passwordResetToken: string, password: string) => Promise<
User | PasswordResetTokenExpiredError | PasswordResetTokenInvalidError | PasswordValidationError
>
Verifies a passwordResetToken by looking for a User which has previously had it set using the
setPasswordResetToken()
method, and checks that the token is valid and has not expired.
If valid, the User’s credentials will be updated with the new password.
changeNativeIdentifier
(ctx: RequestContext, userId: ID, newIdentifier: string) =>
setIdentifierChangeToken
(ctx: RequestContext, user: User) => Promise<User>
identifierChangeToken
as part of the User email address change
flow.
changeIdentifierByToken
(ctx: RequestContext, token: string) => Promise<
| { user: User; oldIdentifier: string }
| IdentifierChangeTokenInvalidError
| IdentifierChangeTokenExpiredError
>
setIdentifierChangeToken()
method.
updatePassword
(ctx: RequestContext, userId: ID, currentPassword: string, newPassword: string) => Promise<boolean | InvalidCredentialsError | PasswordValidationError>