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.

Hey there!

As this topic is related to Rules - Hooks - Actions and Rules & Hooks are being deprecated soon I’m excited to let you know about our next Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

Learn more here!