From da787cfe43aa947996410fb6efcbcbace845be85 Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Sat, 23 Aug 2025 11:17:28 +0530 Subject: [PATCH] Removed the FCM token from login DTO and logic of adding FCM token to database from mobile login API --- .../Dtos/Authentication/LoginDto.cs | 7 ----- .../Controllers/AuthController.cs | 29 +------------------ 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/Marco.Pms.Model/Dtos/Authentication/LoginDto.cs b/Marco.Pms.Model/Dtos/Authentication/LoginDto.cs index 18ff0ae..5e32c8b 100644 --- a/Marco.Pms.Model/Dtos/Authentication/LoginDto.cs +++ b/Marco.Pms.Model/Dtos/Authentication/LoginDto.cs @@ -5,11 +5,4 @@ public required string Username { get; set; } public required string Password { get; set; } } - - public class MobileLoginDto - { - public required string Username { get; set; } - public required string Password { get; set; } - public required string FcmToken { get; set; } - } } diff --git a/Marco.Pms.Services/Controllers/AuthController.cs b/Marco.Pms.Services/Controllers/AuthController.cs index d2944a0..784bf00 100644 --- a/Marco.Pms.Services/Controllers/AuthController.cs +++ b/Marco.Pms.Services/Controllers/AuthController.cs @@ -127,7 +127,7 @@ namespace MarcoBMS.Services.Controllers /// An IActionResult containing the authentication tokens or an error response. [HttpPost("login-mobile")] - public async Task LoginMobile([FromBody] MobileLoginDto loginDto) + 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"); @@ -225,33 +225,6 @@ namespace MarcoBMS.Services.Controllers // Return a successful response with the generated tokens. _logger.LogInfo("User {Username} logged in successfully.", user.UserName); - var existingFCMTokenMapping = await _context.FCMTokenMappings.Where(ft => ft.FcmToken == loginDto.FcmToken).ToListAsync(); - - if (existingFCMTokenMapping.Any()) - { - _context.FCMTokenMappings.RemoveRange(existingFCMTokenMapping); - } - - var fcmTokenMapping = new FCMTokenMapping - { - EmployeeId = emp.Id, - FcmToken = loginDto.FcmToken, - ExpiredAt = DateTime.UtcNow.AddDays(6), - TenantId = emp.TenantId - }; - _context.FCMTokenMappings.Add(fcmTokenMapping); - - _logger.LogInfo("New FCM Token registering for employee {EmployeeId}", emp.Id); - - _ = Task.Run(async () => - { - // --- 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. - await _firebase.SendLoginOnAnotherDeviceMessageAsync(emp.Id, loginDto.FcmToken, tenantId); - - }); - try { await _context.SaveChangesAsync();