diff --git a/Marco.Pms.Services/Controllers/AuthController.cs b/Marco.Pms.Services/Controllers/AuthController.cs
index b0f86f4..cbc17da 100644
--- a/Marco.Pms.Services/Controllers/AuthController.cs
+++ b/Marco.Pms.Services/Controllers/AuthController.cs
@@ -146,8 +146,20 @@ namespace MarcoBMS.Services.Controllers
}
[HttpPost("login-mobile")]
+ ///
+ /// Handles mobile user login, validates credentials, sends a test push notification,
+ /// and generates JWT, Refresh, and MPIN tokens upon successful authentication.
+ ///
+ /// Data Transfer Object containing the user's login credentials and device token.
+ /// An IActionResult containing the authentication tokens or an error response.
public async Task LoginMobile([FromBody] LoginDto loginDto)
{
+ // Log the start of the login attempt for traceability.
+ _logger.LogInfo("Login attempt initiated for user: {Username}", loginDto.Username ?? "N/A");
+
+ // --- Push Notification Section ---
+ // This section attempts to send a test push notification to the user's device.
+ // It's designed to fail gracefully and handle invalid Firebase Cloud Messaging (FCM) tokens.
var message = new Message()
{
Token = loginDto.DeviceToken,
@@ -157,95 +169,135 @@ namespace MarcoBMS.Services.Controllers
Body = "This is a test message"
}
};
+
try
{
+ // Attempt to send the message via Firebase.
string response = await FirebaseMessaging.DefaultInstance.SendAsync(message);
- _logger.LogInfo("Successfully sent message: {MessageId}", response);
+ _logger.LogInfo("Successfully sent test push notification. MessageId: {MessageId}", response);
}
catch (FirebaseMessagingException ex)
{
- _logger.LogError("Error sending push notification. : {Error}", ex.Message);
+ // Log the specific Firebase error.
+ _logger.LogError("Error sending push notification: {Error}", ex.Message);
- // Check for the specific error codes that indicate an invalid token
+ // Check for specific error codes that indicate an invalid or unregistered token.
if (ex.MessagingErrorCode == MessagingErrorCode.Unregistered ||
ex.MessagingErrorCode == MessagingErrorCode.InvalidArgument)
{
- _logger.LogWarning("FCM token is invalid and should be deleted: {Token}", loginDto.DeviceToken);
+ _logger.LogWarning("FCM token is invalid and should be deleted from the database: {Token}", loginDto.DeviceToken ?? string.Empty);
- // Add your logic here to remove the invalid token from your database
- // await YourTokenService.DeleteTokenAsync(recordAttendanceDot.DeviceToken);
+ // TODO: Implement the logic here to remove the invalid token from your database.
+ // Example: await YourTokenService.DeleteTokenAsync(loginDto.DeviceToken);
}
}
- // Validate input DTO
- if (loginDto == null || string.IsNullOrWhiteSpace(loginDto.Username) || string.IsNullOrWhiteSpace(loginDto.Password))
+
+ try
{
- _logger.LogWarning("Login failed: User not found for input {Username}", loginDto.Username ?? string.Empty);
- return BadRequest(ApiResponse