How to LoginWithRedirect to specific signup provider such as Google, Yahoo, etc

Hi @jonatan.lavado,

Yes! I apologize for misunderstanding. You can add the connection.name or connection.id to the user’s ID Token as a custom claim and access that property in the front end. See below Action code example:

exports.onExecutePostLogin = async (event, api) => {
  api.idToken.setCustomClaim("connection name: ", event.connection.name);
  api.idToken.setCustomClaim("connection id: ", event.connection.id);
};

In your application, you can do something like this:

  const { user, getIdTokenClaims } = useAuth0();
  const [claims, setClaims] = useState(null);

      {isAuthenticated && (
        <>
          <button onClick={async () => setClaims(await getIdTokenClaims())}>
            Get id_token claims
          </button>
          {claims && (
            <pre>id_token_claims: {JSON.stringify(claims, null, 2)}</pre>
          )}
        </>
      )}

Once the Action is deployed and the above code is added, you can see the claims in the ID Token and use the connection information as you see fit. Please note that the above code is intended to be an example only and should be thoroughly tested in a development environment before being added to production.

Referencing: auth0-react/static/index.html at 6429fdd31959548906a2ee1ecc8ec4d3a137ebc3 · auth0/auth0-react · GitHub

Please let me know if you have any additional questions!

Best,

Mary Beth

1 Like