Skip to main content
Skip to main content
You're viewing the documentation for v1, which isn't the latest Medusa version.Latest documentation

AuthService

Can authenticate a user based on email password combination

constructor​

Parameters​

__namedParametersInjectedDependenciesRequired

Properties​

manager_EntityManagerRequired
transactionManager_undefined | EntityManagerRequired
__container__anyRequired
userService_UserServiceRequired
customerService_CustomerServiceRequired
logger_LoggerRequired
__configModule__Record<string, unknown>
__moduleDeclaration__Record<string, unknown>

Accessors​

activeManager_​

Returns​

EntityManagerEntityManagerRequired

Methods​

withTransaction​

Parameters​

transactionManagerEntityManager

Returns​

thisthisRequired

shouldRetryTransaction_​

Parameters​

errRecord<string, unknown> | objectRequired

Returns​

booleanbooleanRequired

atomicPhase_​

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​

TResultobjectRequired
TErrorobjectRequired

Parameters​

work(transactionManager: EntityManager) => Promise<TResult>Required
the transactional work to be done
isolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>
the isolation level to be used for the work.
maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>
Potential error handler

Returns​

PromisePromise<TResult>Required
the result of the transactional work

comparePassword_​

Verifies if a password is valid given the provided password hash

Parameters​

passwordstringRequired
the raw password to check
hashstringRequired
the hash to compare against

Returns​

PromisePromise<boolean>Required
the result of the comparison

authenticateAPIToken​

Authenticates a given user with an API token

Parameters​

tokenstringRequired
the api_token of the user to authenticate

Returns​

PromisePromise<AuthenticateResult>Required
success: whether authentication succeeded user: the user document if authentication succeeded error: a string with the error message

authenticate​

Authenticates a given user based on an email, password combination. Uses scrypt to match password with hashed value.

Parameters​

emailstringRequired
the email of the user
passwordstringRequired
the password of the user

Returns​

PromisePromise<AuthenticateResult>Required
success: whether authentication succeeded user: the user document if authentication succeeded error: a string with the error message

authenticateCustomer​

Authenticates a customer based on an email, password combination. Uses scrypt to match password with hashed value.

Parameters​

emailstringRequired
the email of the user
passwordstringRequired
the password of the user

Returns​

PromisePromise<AuthenticateResult>Required
success: whether authentication succeeded customer: the customer document if authentication succeded error: a string with the error message
Was this section helpful?