Problem/Motivation
I have a site in which users can authenticate through openid_connect, but when a user tries to log in he gets the following error:
RuntimeException: User already logged in in Drupal\openid_connect\OpenIDConnect->completeAuthorization() (line 303 of modules/contrib/openid_connect/src/OpenIDConnect.php).
Drupal\openid_connect\Controller\OpenIDConnectRedirectController->authenticate('legis_sso')
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 49)
Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Therefore it is not possible to log in correctly, what can I do in this case?
Comments
Comment #2
lejuanchis commentedComment #3
rakshith.thotada commentedAdding try catch exception to handle already logged in Users.
Comment #4
rakshith.thotada commentedUpdated Patch
Comment #5
jcnventuraThe suggested code could definitively be better.
The code now is saying, an unknown error occurred since the user is already logged in, and throws an exception to be handled by a higher-level code that knows what is happening. The suggested code immediately grabs that exception (making it useless), and logs a warning. Way better to never throw the exception at all if that's the suggested improvement. Or let the exception as is, and catch it where the call was made.
Comment #6
jcnventuraSeems like this is now a duplicate of #3265805: Make login not fail when user is already logged in