driver to user id

This commit is contained in:
2026-01-07 13:26:31 +01:00
parent 0db80fa98d
commit 94d60527f4
27 changed files with 856 additions and 1170 deletions

View File

@@ -13,6 +13,11 @@ import {
type SignupApplicationError,
type SignupInput,
} from '@core/identity/application/use-cases/SignupUseCase';
import {
SignupSponsorUseCase,
type SignupSponsorApplicationError,
type SignupSponsorInput,
} from '@core/identity/application/use-cases/SignupSponsorUseCase';
import {
ForgotPasswordUseCase,
type ForgotPasswordApplicationError,
@@ -36,11 +41,12 @@ import {
LOGIN_USE_CASE_TOKEN,
LOGOUT_USE_CASE_TOKEN,
SIGNUP_USE_CASE_TOKEN,
SIGNUP_SPONSOR_USE_CASE_TOKEN,
FORGOT_PASSWORD_USE_CASE_TOKEN,
RESET_PASSWORD_USE_CASE_TOKEN,
} from './AuthProviders';
import type { AuthSessionDTO } from './dtos/AuthDto';
import { LoginParamsDTO, SignupParamsDTO } from './dtos/AuthDto';
import { LoginParamsDTO, SignupParamsDTO, SignupSponsorParamsDTO } from './dtos/AuthDto';
import { AuthSessionPresenter } from './presenters/AuthSessionPresenter';
import type { CommandResultDTO } from './presenters/CommandResultPresenter';
import { CommandResultPresenter } from './presenters/CommandResultPresenter';
@@ -72,6 +78,7 @@ export class AuthService {
private readonly identitySessionPort: IdentitySessionPort,
@Inject(LOGIN_USE_CASE_TOKEN) private readonly loginUseCase: LoginUseCase,
@Inject(SIGNUP_USE_CASE_TOKEN) private readonly signupUseCase: SignupUseCase,
@Inject(SIGNUP_SPONSOR_USE_CASE_TOKEN) private readonly signupSponsorUseCase: SignupSponsorUseCase,
@Inject(LOGOUT_USE_CASE_TOKEN) private readonly logoutUseCase: LogoutUseCase,
@Inject(FORGOT_PASSWORD_USE_CASE_TOKEN) private readonly forgotPasswordUseCase: ForgotPasswordUseCase,
@Inject(RESET_PASSWORD_USE_CASE_TOKEN) private readonly resetPasswordUseCase: ResetPasswordUseCase,
@@ -139,6 +146,40 @@ export class AuthService {
};
}
async signupSponsor(params: SignupSponsorParamsDTO): Promise<AuthSessionDTO> {
this.logger.debug(`[AuthService] Attempting sponsor signup for email: ${params.email}`);
this.authSessionPresenter.reset();
const input: SignupSponsorInput = {
email: params.email,
password: params.password,
displayName: params.displayName,
companyName: params.companyName,
};
const result = await this.signupSponsorUseCase.execute(input);
if (result.isErr()) {
const error = result.unwrapErr() as SignupSponsorApplicationError;
throw new Error(mapApplicationErrorToMessage(error, 'Sponsor signup failed'));
}
const userDTO = this.authSessionPresenter.responseModel;
const inferredRole = inferDemoRoleFromEmail(userDTO.email);
const session = await this.identitySessionPort.createSession({
id: userDTO.userId,
displayName: userDTO.displayName,
email: userDTO.email,
...(inferredRole ? { role: inferredRole } : {}),
});
return {
token: session.token,
user: userDTO,
};
}
async loginWithEmail(params: LoginParamsDTO): Promise<AuthSessionDTO> {
this.logger.debug(`[AuthService] Attempting login for email: ${params.email}`);