Login as another user from the rule

I’m trying to link users via the rule.
First the user logs in with email and password. Then the user may log in with a code from the email.
If a user with the same email already exists I find it in a rule and link the current user to the found one (the found one is a primary user).
In this case, the current user is deleted but the returned access token contains the sub (user id) of the removed user. So the access token is not valid.

What I need is to log in as that found user. So my app will receive the valid access token. Is it possible?

I can also link the found user to the current (the current is a primary user) and the problem disappears. However, in such a case the found user will be deleted. And if such a user was logged in he will be logged out automatically. The system is architected in a way that login with a password will be always first. So, at the moment of linking the user may already be logged in.