Mail verification problem

After the user registers, a link is sent by email to confirm the email. If the user is already logged into Keycloak under one account, and follows the link to confirm the mail of another account, a window will be displayed - You are already logged into Keycloak, and the mail will not be confirmed.

How to achieve this behavior so that the mail of the second account is confirmed and Keycloak switches to the second account.

Keycloak does not know that account A and account B are possessed by the same person. From a security posture, if I send a confirmation email link to Bill and a user, Jeff, clicks the link I would absolutely not want to count that as valid because Jeff isn’t Bill, even if both accounts are owned by the same person or entity.

Within Keycloak I’m not sure if there is an answer via configurations, but you could create a custom Realm endpoint for email confirmation or override the existing Theme to add custom logic - I would advise you to consult a security expert in the correct approach but I’d think prompting the user to log out and re-issue the confirmation link via email would be safe.