Linking passwordless email identity to primary identity

We are trying to achieve behaviour like this:

  1. User example@example.com exists in a database connection
  2. User orders a passwordless code to login with example@example.com
  3. User enters correct code and logs in with the email connection identity
  4. Auth0 creates a new user to the email connection with example@example.com
  5. We link the email identity to the primary user identity
  6. When login completes (actions / rules / hooks executed) the access token should have the primary identity user id as sub

The only part which we cannot figure out is the step 6. The login flow completes with the email connection users id in the sub.

Related thread: