Help in link google account after user login

Hello,

I’m currently working on establishing a user flow with the following steps:

  1. Users log in using their username and password.
  2. If no social account is linked to their profile, they are prompted to log in using Google.
  3. Once logged in with Google, their account is linked to their social account.
  4. For users who already have a linked social account, they can proceed with a normal login process.

To implement this, I attempted to create a new provider using Java and integrate it as a new step in the authentication process. However, I encountered issues. When using the identityProviderAuthnRequest method, it successfully logs in with a social account but creates a new user. Alternatively, using identityProviderLinkRequest results in an error, indicating that the user is not logged in.

I am seeking guidance on how to achieve the intended flow correctly. If anyone has insights or directions on the correct approach, I would greatly appreciate your assistance. Feel free to share any specific steps or recommendations to resolve the issues mentioned.

Thank you!