From e3fc6e35b5bcfd4db09b38b96b67ed3776c72c2b Mon Sep 17 00:00:00 2001 From: Mayura Deshmukh Date: Wed, 22 Dec 2021 12:26:44 +0530 Subject: [PATCH] Fixed MOSIP-18903 --- .../controller/LoginController.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/controller/LoginController.java b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/controller/LoginController.java index 50f86525d15..21f67af6b50 100644 --- a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/controller/LoginController.java +++ b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/controller/LoginController.java @@ -161,15 +161,17 @@ public ResponseEntity> validateWithUserIdOtp( "In validateWithUserIdotp method of Login controller for validating user and Otp and providing the access token "); loginValidator.validateId(VALIDATEOTP, userIdOtpRequest.getId(), errors); DataValidationUtil.validate(errors, VALIDATEOTP); - Cookie responseCookie = new Cookie("Authorization", - loginService.getLoginToken(userIdOtpRequest.getRequest().getUserId(), req.getRequestURI())); - responseCookie.setMaxAge((int) -1); - responseCookie.setHttpOnly(true); - responseCookie.setSecure(true); - responseCookie.setPath("/"); - res.addCookie(responseCookie); - - return ResponseEntity.status(HttpStatus.OK).body(loginService.validateWithUserIdOtp(userIdOtpRequest)); + MainResponseDTO responseBody = loginService.validateWithUserIdOtp(userIdOtpRequest); + if (responseBody.getResponse() != null && responseBody.getErrors() == null) { + Cookie responseCookie = new Cookie("Authorization", + loginService.getLoginToken(userIdOtpRequest.getRequest().getUserId(), req.getRequestURI())); + responseCookie.setMaxAge((int) -1); + responseCookie.setHttpOnly(true); + responseCookie.setSecure(true); + responseCookie.setPath("/"); + res.addCookie(responseCookie); + } + return ResponseEntity.status(HttpStatus.OK).body(responseBody); } /**