---
title: "UserService"
generated: true
---
<GenerationInfo sourceFile="packages/core/src/service/services/user.service.ts" sourceLine="38" packageName="@vendure/core" />

Contains methods relating to <DocsLink href="/reference/typescript-api/entities/user#user">User</DocsLink> entities.

```ts title="Signature"
class UserService {
    constructor(connection: TransactionalConnection, configService: ConfigService, roleService: RoleService, passwordCipher: PasswordCipher, verificationTokenGenerator: VerificationTokenGenerator, moduleRef: ModuleRef)
    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>;
    addNativeAuthenticationMethod(ctx: RequestContext, user: User, identifier: string, password?: string) => Promise<User | PasswordValidationError>;
    createAdminUser(ctx: RequestContext, identifier: string, password: string) => Promise<User>;
    softDelete(ctx: RequestContext, userId: ID) => ;
    setVerificationToken(ctx: RequestContext, user: User) => Promise<User>;
    verifyUserByToken(ctx: RequestContext, verificationToken: string, password?: string) => Promise<ErrorResultUnion<VerifyCustomerAccountResult, User>>;
    setPasswordResetToken(ctx: RequestContext, emailAddress: string) => Promise<User | undefined>;
    resetPasswordByToken(ctx: RequestContext, passwordResetToken: string, password: string) => Promise<
        User | PasswordResetTokenExpiredError | PasswordResetTokenInvalidError | PasswordValidationError
    >;
    changeUserAndNativeIdentifier(ctx: RequestContext, userId: ID, newIdentifier: string) => ;
    setIdentifierChangeToken(ctx: RequestContext, user: User) => Promise<User>;
    changeIdentifierByToken(ctx: RequestContext, token: string) => Promise<
        | { user: User; oldIdentifier: string }
        | IdentifierChangeTokenInvalidError
        | IdentifierChangeTokenExpiredError
    >;
    updatePassword(ctx: RequestContext, userId: ID, currentPassword: string, newPassword: string) => Promise<boolean | InvalidCredentialsError | PasswordValidationError>;
}
```

<div className="members-wrapper">

### constructor

<MemberInfo kind="method" type={`(connection: <a href='/reference/typescript-api/data-access/transactional-connection#transactionalconnection'>TransactionalConnection</a>, configService: ConfigService, roleService: <a href='/reference/typescript-api/services/role-service#roleservice'>RoleService</a>, passwordCipher: PasswordCipher, verificationTokenGenerator: VerificationTokenGenerator, moduleRef: ModuleRef) => UserService`}   />


### getUserById

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, userId: <a href='/reference/typescript-api/common/id#id'>ID</a>) => Promise<<a href='/reference/typescript-api/entities/user#user'>User</a> | undefined>`}   />


### getUserByEmailAddress

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, emailAddress: string, userType?: 'administrator' | 'customer') => Promise<<a href='/reference/typescript-api/entities/user#user'>User</a> | undefined>`}   />


### createCustomerUser

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, identifier: string, password?: string) => Promise<<a href='/reference/typescript-api/entities/user#user'>User</a> | PasswordValidationError>`}   />

Creates a new User with the special `customer` Role and using the <DocsLink href="/reference/typescript-api/auth/native-authentication-strategy#nativeauthenticationstrategy">NativeAuthenticationStrategy</DocsLink>.
### addNativeAuthenticationMethod

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, user: <a href='/reference/typescript-api/entities/user#user'>User</a>, identifier: string, password?: string) => Promise<<a href='/reference/typescript-api/entities/user#user'>User</a> | PasswordValidationError>`}   />

Adds a new <DocsLink href="/reference/typescript-api/entities/authentication-method#nativeauthenticationmethod">NativeAuthenticationMethod</DocsLink> to the User. If the <DocsLink href="/reference/typescript-api/auth/auth-options#authoptions">AuthOptions</DocsLink> `requireVerification`
is set to `true` (as is the default), the User will be marked as unverified until the email verification
flow is completed.
### createAdminUser

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, identifier: string, password: string) => Promise<<a href='/reference/typescript-api/entities/user#user'>User</a>>`}   />

Creates a new verified User using the <DocsLink href="/reference/typescript-api/auth/native-authentication-strategy#nativeauthenticationstrategy">NativeAuthenticationStrategy</DocsLink>.
### softDelete

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, userId: <a href='/reference/typescript-api/common/id#id'>ID</a>) => `}   />


### setVerificationToken

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, user: <a href='/reference/typescript-api/entities/user#user'>User</a>) => Promise<<a href='/reference/typescript-api/entities/user#user'>User</a>>`}   />

Sets the <DocsLink href="/reference/typescript-api/entities/authentication-method#nativeauthenticationmethod">NativeAuthenticationMethod</DocsLink> `verificationToken` as part of the User email verification
flow.
### verifyUserByToken

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, verificationToken: string, password?: string) => Promise<<a href='/reference/typescript-api/errors/error-result-union#errorresultunion'>ErrorResultUnion</a><VerifyCustomerAccountResult, <a href='/reference/typescript-api/entities/user#user'>User</a>>>`}   />

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

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, emailAddress: string) => Promise<<a href='/reference/typescript-api/entities/user#user'>User</a> | undefined>`}   />

Sets the <DocsLink href="/reference/typescript-api/entities/authentication-method#nativeauthenticationmethod">NativeAuthenticationMethod</DocsLink> `passwordResetToken` as part of the User password reset
flow.
### resetPasswordByToken

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, passwordResetToken: string, password: string) => Promise<         <a href='/reference/typescript-api/entities/user#user'>User</a> | 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.
### changeUserAndNativeIdentifier

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, userId: <a href='/reference/typescript-api/common/id#id'>ID</a>, newIdentifier: string) => `}   />

Changes the User identifier without an email verification step, so this should be only used when
an Administrator is setting a new email address.
### setIdentifierChangeToken

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, user: <a href='/reference/typescript-api/entities/user#user'>User</a>) => Promise<<a href='/reference/typescript-api/entities/user#user'>User</a>>`}   />

Sets the <DocsLink href="/reference/typescript-api/entities/authentication-method#nativeauthenticationmethod">NativeAuthenticationMethod</DocsLink> `identifierChangeToken` as part of the User email address change
flow.
### changeIdentifierByToken

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, token: string) => Promise<         | { user: <a href='/reference/typescript-api/entities/user#user'>User</a>; oldIdentifier: string }         | IdentifierChangeTokenInvalidError         | IdentifierChangeTokenExpiredError     >`}   />

Changes the User identifier as part of the storefront flow used by Customers to set a
new email address, with the token previously set using the `setIdentifierChangeToken()` method.
### updatePassword

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, userId: <a href='/reference/typescript-api/common/id#id'>ID</a>, currentPassword: string, newPassword: string) => Promise<boolean | InvalidCredentialsError | PasswordValidationError>`}   />

Updates the password for a User with the <DocsLink href="/reference/typescript-api/entities/authentication-method#nativeauthenticationmethod">NativeAuthenticationMethod</DocsLink>.


</div>
