public async Task<ObjectResource<LoginResource>> LoginAsync(LoginPayload payload) { if (payload == null) { return new ObjectResource<LoginResource> { Code = ResourceCodes.NullPayload, Data = null, Message = "Payload cannot be null" }; } string tokenString = string.Empty; bool validUser = Authenticate(payload); if (validUser) { tokenString = tokenGenerator.BuildJWTToken(); if(tokenGenerator == null) { logger.LogError($"unable to generate token for user {payload.Username}"); return new ObjectResource<LoginResource> { Code = ResourceCodes.InvalidToken, Message = "unable to generate Token" }; } logger.LogInformation($"Successfully generated token for {tokenString}"); return new ObjectResource<LoginResource> { Code = ResourceCodes.Success, Data = new LoginResource { Token = tokenString, UserName = payload.Username }, Message = "Login Successful" }; } else { logger.LogError($"Invalid Login payload: {payload} at {DateTime.Now}"); return new ObjectResource<LoginResource> { Code = ResourceCodes.InvalidLoginDetails, Data = null, Message = "password or username is incorrect" }; } }