Skip to main content
Skip to main content

AuthService

internal.internal.AuthService

Can authenticate a user based on email password combination

Properties

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

Accessors

activeManager_

Protected get activeManager_(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Inherited from

TransactionBaseService.activeManager_

Methods

atomicPhase_

Protected atomicPhase_<TResult, TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise<TResult>

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.

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

Inherited from

TransactionBaseService.atomicPhase_


authenticate

authenticate(email, password): Promise<AuthenticateResult>

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<AuthenticateResult>

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<AuthenticateResult>

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<boolean>

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

Inherited from

TransactionBaseService.shouldRetryTransaction_


withTransaction

withTransaction(transactionManager?): AuthService

Parameters

transactionManagerEntityManager

Returns

AuthService

AuthServiceAuthServiceRequired

Inherited from

TransactionBaseService.withTransaction

Was this section helpful?