From 0aa7a60427d2d0bacdd6812d5d4874bd90cefdd3 Mon Sep 17 00:00:00 2001 From: "jan.fetalvero" Date: Wed, 3 Sep 2025 17:20:13 +0800 Subject: [PATCH] Add signedInAlertResponse() to handle already-authenticated users --- gigya_raas/src/GigyaController.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/gigya_raas/src/GigyaController.php b/gigya_raas/src/GigyaController.php index 570df77..30ed4a7 100644 --- a/gigya_raas/src/GigyaController.php +++ b/gigya_raas/src/GigyaController.php @@ -117,7 +117,8 @@ public function gigyaRaasProcessFieldMapping(Request $request): AjaxResponse { * @param \Symfony\Component\HttpFoundation\Request $request * The incoming request object. * - * @return bool|AjaxResponse The Ajax response + * @return \Drupal\Core\Ajax\AjaxResponse + * The Ajax response * * @throws \Drupal\Core\Entity\EntityStorageException */ @@ -438,7 +439,8 @@ public function gigyaRaasLoginAjax(Request $request) { return $response; } - return FALSE; + + return $this->signedInAlertResponse(); } /** @@ -731,4 +733,24 @@ protected function editPhoneNumber($phoneNumber) { return $phoneNumber; } + /** + * Ajax alert shown when an already-authenticated user attempts to log in. + * + * This method logs and returns an Ajax response containing an alert + * message to inform the user that they are already signed in. + * + * @return \Drupal\Core\Ajax\AjaxResponse + * The Ajax response with an alert command. + */ + protected function signedInAlertResponse(): AjaxResponse { + // Log the event for debugging. + \Drupal::logger('gigya_raas')->notice('User attempted to log in while already authenticated.'); + + // Return the AjaxResponse with alert. + $response = new AjaxResponse(); + $response->addCommand(new AlertCommand($this->t("You're already signed in."))); + + return $response; + } + }