Skip to main content

Class: UserService

Provides layer to manipulate users.

Hierarchy

  • TransactionBaseServiceCopy to Clipboard

    UserServiceCopy to Clipboard

Constructors

constructor

new UserService(__namedParametersCopy to Clipboard)

Parameters

NameType
__namedParametersCopy to ClipboardUserServicePropsCopy to Clipboard

Overrides

TransactionBaseService.constructor

Defined in

packages/medusa/src/services/user.ts:47

Properties

__configModule__

ProtectedCopy to Clipboard OptionalCopy to Clipboard ReadonlyCopy to Clipboard __configModule__: RecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>

Inherited from

TransactionBaseService.__configModule__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:10


__container__

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard __container__: anyCopy to Clipboard

Inherited from

TransactionBaseService.__container__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:9


__moduleDeclaration__

ProtectedCopy to Clipboard OptionalCopy to Clipboard ReadonlyCopy to Clipboard __moduleDeclaration__: RecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>

Inherited from

TransactionBaseService.__moduleDeclaration__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:11


analyticsConfigService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard analyticsConfigService_: AnalyticsConfigServiceCopy to Clipboard

Defined in

packages/medusa/src/services/user.ts:42


eventBus_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard eventBus_: EventBusServiceCopy to Clipboard

Defined in

packages/medusa/src/services/user.ts:44


featureFlagRouter_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard featureFlagRouter_: FlagRouterCopy to Clipboard

Defined in

packages/medusa/src/services/user.ts:45


manager_

ProtectedCopy to Clipboard manager_: EntityManagerCopy to Clipboard

Overrides

TransactionBaseService.manager_

Defined in

packages/medusa/src/services/user.ts:40


transactionManager_

ProtectedCopy to Clipboard transactionManager_: EntityManagerCopy to Clipboard

Overrides

TransactionBaseService.transactionManager_

Defined in

packages/medusa/src/services/user.ts:41


userRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard userRepository_: typeof UserRepositoryCopy to Clipboard

Defined in

packages/medusa/src/services/user.ts:43


Events

StaticCopy to Clipboard Events: ObjectCopy to Clipboard

Type declaration

NameType
CREATEDCopy to ClipboardstringCopy to Clipboard
DELETEDCopy to ClipboardstringCopy to Clipboard
PASSWORD_RESETCopy to ClipboardstringCopy to Clipboard
UPDATEDCopy to ClipboardstringCopy to Clipboard

Defined in

packages/medusa/src/services/user.ts:33

Methods

atomicPhase_

ProtectedCopy to Clipboard atomicPhase_<TResultCopy to Clipboard, TErrorCopy to Clipboard>(workCopy to Clipboard, isolationOrErrorHandler?Copy to Clipboard, maybeErrorHandlerOrDontFail?Copy to Clipboard): PromiseCopy to Clipboard<TResultCopy to Clipboard>

Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.

Type parameters

Name
TResultCopy to Clipboard
TErrorCopy to Clipboard

Parameters

NameTypeDescription
workCopy to Clipboard(transactionManagerCopy to Clipboard: EntityManagerCopy to Clipboard) => PromiseCopy to Clipboard<TResultCopy to Clipboard>the transactional work to be done
isolationOrErrorHandler?Copy to ClipboardIsolationLevelCopy to Clipboard | (errorCopy to Clipboard: TErrorCopy to Clipboard) => PromiseCopy to Clipboard<voidCopy to Clipboard | TResultCopy to Clipboard>the isolation level to be used for the work.
maybeErrorHandlerOrDontFail?Copy to Clipboard(errorCopy to Clipboard: TErrorCopy to Clipboard) => PromiseCopy to Clipboard<voidCopy to Clipboard | TResultCopy to Clipboard>Potential error handler

Returns

PromiseCopy to Clipboard<TResultCopy to Clipboard>

the result of the transactional work

Inherited from

TransactionBaseService.atomicPhase_

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:50


create

create(userCopy to Clipboard, passwordCopy to Clipboard): PromiseCopy to Clipboard<UserCopy to Clipboard>

Creates a user with username being validated. Fails if email is not a valid format.

Parameters

NameTypeDescription
userCopy to ClipboardCreateUserInputCopy to Clipboardthe user to create
passwordCopy to ClipboardstringCopy to Clipboarduser's password to hash

Returns

PromiseCopy to Clipboard<UserCopy to Clipboard>

the result of create

Defined in

packages/medusa/src/services/user.ts:179


delete

delete(userIdCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Deletes a user from a given user id.

Parameters

NameTypeDescription
userIdCopy to ClipboardstringCopy to Clipboardthe id of the user to delete. Must be castable as an ObjectId

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

the result of the delete operation.

Defined in

packages/medusa/src/services/user.ts:259


generateResetPasswordToken

generateResetPasswordToken(userIdCopy to Clipboard): PromiseCopy to Clipboard<stringCopy to Clipboard>

Generate a JSON Web token, that will be sent to a user, that wishes to reset password. The token will be signed with the users current password hash as a secret a long side a payload with userId and the expiry time for the token, which is always 15 minutes.

Parameters

NameTypeDescription
userIdCopy to ClipboardstringCopy to Clipboardthe id of the user to reset password for

Returns

PromiseCopy to Clipboard<stringCopy to Clipboard>

the generated JSON web token

Defined in

packages/medusa/src/services/user.ts:323


hashPassword_

hashPassword_(passwordCopy to Clipboard): PromiseCopy to Clipboard<stringCopy to Clipboard>

Hashes a password

Parameters

NameTypeDescription
passwordCopy to ClipboardstringCopy to Clipboardthe value to hash

Returns

PromiseCopy to Clipboard<stringCopy to Clipboard>

hashed password

Defined in

packages/medusa/src/services/user.ts:167


list

list(selectorCopy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<UserCopy to Clipboard[]>

Parameters

NameTypeDescription
selectorCopy to ClipboardFilterableUserPropsCopy to Clipboardthe query object for find
configCopy to ClipboardObjectCopy to Clipboardthe configuration object for the query

Returns

PromiseCopy to Clipboard<UserCopy to Clipboard[]>

the result of the find operation

Defined in

packages/medusa/src/services/user.ts:69


retrieve

retrieve(userIdCopy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<UserCopy to Clipboard>

Gets a user by id. Throws in case of DB Error and if user was not found.

Parameters

NameTypeDescription
userIdCopy to ClipboardstringCopy to Clipboardthe id of the user to get.
configCopy to ClipboardFindConfigCopy to Clipboard<UserCopy to Clipboard>query configs

Returns

PromiseCopy to Clipboard<UserCopy to Clipboard>

the user document.

Defined in

packages/medusa/src/services/user.ts:82


retrieveByApiToken

retrieveByApiToken(apiTokenCopy to Clipboard, relations?Copy to Clipboard): PromiseCopy to Clipboard<UserCopy to Clipboard>

Gets a user by api token. Throws in case of DB Error and if user was not found.

Parameters

NameTypeDefault valueDescription
apiTokenCopy to ClipboardstringCopy to ClipboardundefinedCopy to Clipboardthe token of the user to get.
relationsCopy to ClipboardstringCopy to Clipboard[][]Copy to Clipboardrelations to include with the user.

Returns

PromiseCopy to Clipboard<UserCopy to Clipboard>

the user document.

Defined in

packages/medusa/src/services/user.ts:113


retrieveByEmail

retrieveByEmail(emailCopy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<UserCopy to Clipboard>

Gets a user by email. Throws in case of DB Error and if user was not found.

Parameters

NameTypeDescription
emailCopy to ClipboardstringCopy to Clipboardthe email of the user to get.
configCopy to ClipboardFindConfigCopy to Clipboard<UserCopy to Clipboard>query config

Returns

PromiseCopy to Clipboard<UserCopy to Clipboard>

the user document.

Defined in

packages/medusa/src/services/user.ts:142


setPassword_

setPassword_(userIdCopy to Clipboard, passwordCopy to Clipboard): PromiseCopy to Clipboard<UserCopy to Clipboard>

Sets a password for a user Fails if no user exists with userId and if the hashing of the new password does not work.

Parameters

NameTypeDescription
userIdCopy to ClipboardstringCopy to Clipboardthe userId to set password for
passwordCopy to ClipboardstringCopy to Clipboardthe old password to set

Returns

PromiseCopy to Clipboard<UserCopy to Clipboard>

the result of the update operation

Defined in

packages/medusa/src/services/user.ts:294


shouldRetryTransaction_

ProtectedCopy to Clipboard shouldRetryTransaction_(errCopy to Clipboard): booleanCopy to Clipboard

Parameters

NameType
errCopy to ClipboardRecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard> | { codeCopy to Clipboard: stringCopy to Clipboard }

Returns

booleanCopy to Clipboard

Inherited from

TransactionBaseService.shouldRetryTransaction_

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:31


update

update(userIdCopy to Clipboard, updateCopy to Clipboard): PromiseCopy to Clipboard<UserCopy to Clipboard>

Updates a user.

Parameters

NameTypeDescription
userIdCopy to ClipboardstringCopy to Clipboardid of the user to update
updateCopy to ClipboardUpdateUserInputCopy to Clipboardthe values to be updated on the user

Returns

PromiseCopy to Clipboard<UserCopy to Clipboard>

the result of create

Defined in

packages/medusa/src/services/user.ts:213


withTransaction

withTransaction(transactionManager?Copy to Clipboard): UserServiceCopy to Clipboard

Parameters

NameType
transactionManager?Copy to ClipboardEntityManagerCopy to Clipboard

Returns

UserServiceCopy to Clipboard

Inherited from

TransactionBaseService.withTransaction

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:14