middleware test
This commit is contained in:
@@ -51,6 +51,20 @@ function mapApplicationErrorToMessage(error: { details?: { message?: string } }
|
||||
return error?.details?.message ?? fallback;
|
||||
}
|
||||
|
||||
function inferDemoRoleFromEmail(email: string): AuthSessionDTO['user']['role'] | undefined {
|
||||
const normalized = email.trim().toLowerCase();
|
||||
|
||||
if (normalized === 'demo.driver@example.com') return 'driver';
|
||||
if (normalized === 'demo.sponsor@example.com') return 'sponsor';
|
||||
if (normalized === 'demo.owner@example.com') return 'league-owner';
|
||||
if (normalized === 'demo.steward@example.com') return 'league-steward';
|
||||
if (normalized === 'demo.admin@example.com') return 'league-admin';
|
||||
if (normalized === 'demo.systemowner@example.com') return 'system-owner';
|
||||
if (normalized === 'demo.superadmin@example.com') return 'super-admin';
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export class AuthService {
|
||||
constructor(
|
||||
@Inject(LOGGER_TOKEN) private readonly logger: Logger,
|
||||
@@ -111,10 +125,12 @@ export class AuthService {
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -144,12 +160,15 @@ export class AuthService {
|
||||
const sessionOptions = params.rememberMe !== undefined
|
||||
? { rememberMe: params.rememberMe }
|
||||
: undefined;
|
||||
|
||||
|
||||
const inferredRole = inferDemoRoleFromEmail(userDTO.email);
|
||||
|
||||
const session = await this.identitySessionPort.createSession(
|
||||
{
|
||||
id: userDTO.userId,
|
||||
displayName: userDTO.displayName,
|
||||
email: userDTO.email,
|
||||
...(inferredRole ? { role: inferredRole } : {}),
|
||||
},
|
||||
sessionOptions
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user