Did you try Redis for this task ? You can generate random 6-digit code (on backend) when you send to email (or whatever trigers API route) and add it to Redis. Finally, compare them when the user paste code from mail and request API.