|
@@ -1,11 +1,12 @@
|
|
|
// apps/box-app-api/src/auth/auth.service.ts
|
|
// apps/box-app-api/src/auth/auth.service.ts
|
|
|
-import { Injectable } from '@nestjs/common';
|
|
|
|
|
|
|
+import { Injectable, Logger } from '@nestjs/common';
|
|
|
import { JwtService } from '@nestjs/jwt';
|
|
import { JwtService } from '@nestjs/jwt';
|
|
|
import { UserLoginEventPayload } from '@box/common/events/user-login-event.dto';
|
|
import { UserLoginEventPayload } from '@box/common/events/user-login-event.dto';
|
|
|
import { RabbitmqPublisherService } from '../../rabbitmq/rabbitmq-publisher.service';
|
|
import { RabbitmqPublisherService } from '../../rabbitmq/rabbitmq-publisher.service';
|
|
|
|
|
|
|
|
@Injectable()
|
|
@Injectable()
|
|
|
export class AuthService {
|
|
export class AuthService {
|
|
|
|
|
+ private readonly logger = new Logger(AuthService.name);
|
|
|
constructor(
|
|
constructor(
|
|
|
private readonly jwtService: JwtService,
|
|
private readonly jwtService: JwtService,
|
|
|
private readonly rabbitmqPublisher: RabbitmqPublisherService,
|
|
private readonly rabbitmqPublisher: RabbitmqPublisherService,
|
|
@@ -51,6 +52,7 @@ export class AuthService {
|
|
|
|
|
|
|
|
// 4) Fire-and-forget publish (but wait for broker confirm)
|
|
// 4) Fire-and-forget publish (but wait for broker confirm)
|
|
|
try {
|
|
try {
|
|
|
|
|
+ this.logger.log(`Publishing user login event for uid=${uid}`);
|
|
|
await this.rabbitmqPublisher.publishUserLogin(loginEvent);
|
|
await this.rabbitmqPublisher.publishUserLogin(loginEvent);
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
// Decide your policy:
|
|
// Decide your policy:
|
|
@@ -58,6 +60,13 @@ export class AuthService {
|
|
|
// - Or throw to fail login if stats are critical.
|
|
// - Or throw to fail login if stats are critical.
|
|
|
// For now, let's log and continue.
|
|
// For now, let's log and continue.
|
|
|
// If you want stricter behaviour, re-throw.
|
|
// If you want stricter behaviour, re-throw.
|
|
|
|
|
+ const errorMessage =
|
|
|
|
|
+ error instanceof Error ? error.message : String(error);
|
|
|
|
|
+ const errorStack = error instanceof Error ? error.stack : undefined;
|
|
|
|
|
+ this.logger.error(
|
|
|
|
|
+ `Failed to publish user login event for uid=${uid}: ${errorMessage}`,
|
|
|
|
|
+ errorStack,
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return { accessToken };
|
|
return { accessToken };
|