How to implement a Referral system?

@Jici So I have managed to take a step forward but it is still not perfect.

Basically, if you Do a search for User, filter: id contain id:first item this will return the user who have referred. If empty, this mean that the code may be wrong

This is the workflow that I use to generate a Refer code and send it via email.

I could not understand how to do the search for the code/email in the sign up flow. This is what I have done. This workflow is able to check if the field is empty or not but it doesn’t check the validity. What am I doing wrong here ?