Spaces:
Sleeping
Sleeping
Download src/modules/auth/application/useCases/SignupUseCase.ts from fouadkhalid123/asd: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/fouadkhalid123/asd/resolve/main/src/modules/auth/application/useCases/SignupUseCase.ts
- Command line
-
hf download hf://spaces/fouadkhalid123/asd/src/modules/auth/application/useCases/SignupUseCase.ts
-
curl -L -o SignupUseCase.ts https://huggingface.co/spaces/fouadkhalid123/asd/resolve/main/src/modules/auth/application/useCases/SignupUseCase.ts
1.62 kB
| import jwt from "jsonwebtoken"; | |
| import crypto from "crypto"; | |
| import { JtiStore } from "../../../../libs/shared/infrastructure/memory/JtiStore"; | |
| import { env } from "../../../../config/env"; | |
| import { UnitOfWorkFactory } from "../../../../libs/shared/infrastructure/postgres/unitOfWork/UnitOfWorkFactory"; | |
| import { IUnitOfWork } from "../../../../libs/shared/infrastructure/postgres/unitOfWork/IUnitOfWork"; | |
| import { TenantPlan } from "../../../../libs/shared/domain/valueObjects/TenantContext"; | |
| import { AuthOrchestrator } from "../orchestrator/AuthOrchestrator"; | |
| export interface SignupInput { | |
| adminEmail: string; | |
| adminPassword: string; | |
| companyName: string; | |
| shopDomain: string; | |
| plan?: TenantPlan; | |
| } | |
| export interface SignupOutput { | |
| token: string; | |
| user: { | |
| id: string; | |
| email: string; | |
| organizationId: string; | |
| storeId: string; | |
| }; | |
| } | |
| export class SignupUseCase { | |
| private readonly orchestrator: AuthOrchestrator; | |
| constructor(private readonly uowFactory: UnitOfWorkFactory) { | |
| this.orchestrator = new AuthOrchestrator(); | |
| } | |
| async execute(input: SignupInput): Promise<SignupOutput> { | |
| return this.uowFactory.execute(async (uow: IUnitOfWork) => { | |
| // 1. Ensure email not already taken | |
| const existing = await uow.users.findByEmail(input.adminEmail); | |
| if (existing) { | |
| throw Object.assign(new Error("Email already registered"), { statusCode: 409 }); | |
| } | |
| // 2. Delegate to Orchestrator | |
| return this.orchestrator.signUp(uow, input); | |
| }); | |
| } | |
| } | |