Skip to main content
Skip to main content

AuthService

Can authenticate a user based on email password combination

Constructors

constructor

**new AuthService**(«destructured»)

Parameters
__namedParametersInjectedDependenciesRequired

Properties

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

Accessors

activeManager_

Protected activeManager_: [object Object]

Methods

atomicPhase_

Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;

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

Promise<TResult>

PromisePromise<TResult>Required
the result of the transactional work

authenticate

**authenticate**(email, password): Promise&#60;[AuthenticateResult](/references/services/types/AuthenticateResult)&#62;

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

Promise<AuthenticateResult>

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

authenticateAPIToken

**authenticateAPIToken**(token): Promise&#60;[AuthenticateResult](/references/services/types/AuthenticateResult)&#62;

Authenticates a given user with an API token

Parameters
tokenstringRequired
the api_token of the user to authenticate
Returns

Promise<AuthenticateResult>

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

authenticateCustomer

**authenticateCustomer**(email, password): Promise&#60;[AuthenticateResult](/references/services/types/AuthenticateResult)&#62;

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

Promise<AuthenticateResult>

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

comparePassword_

Protected **comparePassword_**(password, hash): Promise&#60;boolean&#62;

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

Promise<boolean>

PromisePromise<boolean>Required
the result of the comparison

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters
errRecord<string, unknown> | { code: string }Required
Returns

boolean

booleanboolean

withTransaction

**withTransaction**(transactionManager?): [AuthService](/references/services/classes/AuthService)

Parameters
transactionManagerEntityManager
Returns

AuthService

AuthServiceAuthServiceRequired
Was this section helpful?