This guide describes how to configure @jmlq/auth in a host by implementing its ports and building the container.
AuthServiceFactory.create(...) requires these dependencies:
IUserRepositoryPortICredentialRepositoryPortITokenServicePortIPasswordResetTokenPortIEmailVerificationTokenPort
The core only knows interfaces. The concrete implementation lives in your infrastructure.
Real example (simplified) of the composition:
import { AuthServiceFactory } from "@jmlq/auth";
const auth = AuthServiceFactory.create(
userRepository,
credentialRepository,
tokenService,
passwordResetToken,
emailVerificationToken,
{
// hashing
bcryptSaltRounds: 10,
// session TTLs
accessTokenTtl: "15m",
refreshTokenTtl: "7d",
// flow TTLs (optional)
// passwordResetTokenTtl: "30m",
// emailVerificationTokenTtl: "1d",
},
);- If
passwordPolicyis not provided, it usesDefaultPasswordPolicy. - Builds
BcryptPasswordHasherwithbcryptSaltRounds. - Builds
TokenSessionServicewith TTLs (accessTokenTtl/refreshTokenTtl). - Instantiates use cases and returns an
IAuthServiceContainer.
Align core TTLs with the host strategy:
- Short access (
15mtypical) - Long refresh (
7dtypical)
Ensure your ICredentialRepositoryPort persists the relationship:
(userId, sessionId)- current refresh token (for rotation)
The host must decide:
- how to issue the token (e.g., random/signed)
- persistence or validation strategy
- expiration (TTL)
Then adapt it to the core via IPasswordResetTokenPort and IEmailVerificationTokenPort.
- Implement
IUserRepositoryPort - Implement
ICredentialRepositoryPort(session/refresh persistence) - Implement
ITokenServicePort(access/refresh issue/verify) - Implement
IPasswordResetTokenPort - Implement
IEmailVerificationTokenPort - Build container with
AuthServiceFactory.create(...)