feat(server): improve logs (#8977)

This commit is contained in:
darkskygit
2024-12-03 06:47:16 +00:00
parent 27d2735a64
commit eb64231899
8 changed files with 35 additions and 16 deletions
@@ -75,7 +75,7 @@ export class AuthController {
@Body() params?: { email: string }
): Promise<PreflightResponse> {
if (!params?.email) {
throw new InvalidEmail();
throw new InvalidEmail({ email: 'not provided' });
}
validators.assertValidEmail(params.email);
@@ -171,7 +171,7 @@ export class AuthController {
// verify domain has MX, SPF, DMARC records
const [name, domain, ...rest] = email.split('@');
if (rest.length || !domain) {
throw new InvalidEmail();
throw new InvalidEmail({ email });
}
const [mx, spf, dmarc] = await Promise.allSettled([
resolveMx(domain).then(t => t.map(mx => mx.exchange).filter(Boolean)),
@@ -183,11 +183,11 @@ export class AuthController {
),
]).then(t => t.filter(t => t.status === 'fulfilled').map(t => t.value));
if (!mx?.length || !spf?.length || !dmarc?.length) {
throw new InvalidEmail();
throw new InvalidEmail({ email });
}
// filter out alias emails
if (name.includes('+') || name.includes('.')) {
throw new InvalidEmail();
throw new InvalidEmail({ email });
}
}
}
@@ -5,7 +5,7 @@ import { InvalidEmail, InvalidPasswordLength } from '../../fundamentals';
export function assertValidEmail(email: string) {
const result = z.string().email().safeParse(email);
if (!result.success) {
throw new InvalidEmail();
throw new InvalidEmail({ email });
}
}