2026-10-03 10:36:03 +00:00
|
|
|
import { randomBytes } from "node:crypto";
|
|
|
|
|
|
|
|
|
|
import type { Sequelize } from "sequelize";
|
|
|
|
|
|
|
|
|
|
import { IdentityUseCases } from "./application/identity.use-cases";
|
|
|
|
|
import { UserInputMapper } from "./application/user-input.mapper";
|
|
|
|
|
import { registerIdentityRoutes } from "./infrastructure/http/identity.routes";
|
|
|
|
|
import { requireAuthenticated } from "./infrastructure/http/require-authenticated";
|
|
|
|
|
import { migrateIdentity } from "./infrastructure/persistence/migrate-identity";
|
|
|
|
|
import { SequelizeUserRepository } from "./infrastructure/persistence/sequelize-user.repository";
|
|
|
|
|
import { initializeIdentityModels } from "./infrastructure/persistence/user.model";
|
|
|
|
|
import { UserPersistenceMapper } from "./infrastructure/persistence/user-persistence.mapper";
|
|
|
|
|
import { ScryptPasswordHasher } from "./infrastructure/security/scrypt-password-hasher";
|
|
|
|
|
|
|
|
|
|
export { migrateIdentity };
|
2026-10-10 10:01:58 +00:00
|
|
|
|
2026-10-03 10:36:03 +00:00
|
|
|
export async function createIdentityModule(database: Sequelize, origin: string) {
|
|
|
|
|
initializeIdentityModels(database);
|
|
|
|
|
const passwords = new ScryptPasswordHasher();
|
|
|
|
|
const users = new SequelizeUserRepository(database, new UserPersistenceMapper());
|
|
|
|
|
const useCases = new IdentityUseCases(
|
|
|
|
|
users,
|
|
|
|
|
passwords,
|
|
|
|
|
new UserInputMapper(passwords),
|
|
|
|
|
await passwords.hash(randomBytes(32).toString("hex"))
|
|
|
|
|
);
|
2026-10-10 10:01:58 +00:00
|
|
|
|
2026-10-03 10:36:03 +00:00
|
|
|
return {
|
|
|
|
|
authenticate: requireAuthenticated(useCases),
|
|
|
|
|
register: (app: Parameters<typeof registerIdentityRoutes>[0]) =>
|
|
|
|
|
registerIdentityRoutes(app, useCases, origin),
|
|
|
|
|
};
|
|
|
|
|
}
|