Custom email confirmation logic after registration (confirmation code instead of link)

Hello,

I’m posting this after searching on the internet and documentation for a little while how to implement a custom logic for validation users emails after registration.

By default, Strapi sends a confirmation email to users which have to click on a link to validate their account. I would like to send an email containing only a 6-digits code that the user will be able to enter on a form input to validate their account.

I’ve found a potential solution which would be to use a middleware after a successful user registration to send such an email. However, that does not seem to be a clean approach and it would imply deactivating the default email confirmation workflow (i.e. the user is automatically set to confirmed=true, needs to be “unconfirmed” and then to receive a randomly generated 6-digits code to be confirmed again).

Could anyone advise me on a proper approach to get this email confirmation by code working that would remain close to the default confirmation link workflow?
An idea I had would be to basically change the confirmation code/token generation on Strapi’s end to generate a 6-digit code instead of a long token but I have no clue on how to do that.

Thank you in advance!

Kind regards,
Boris

Hello,

Just a little up regarding my above message, if anyone has any idea on how to handle that.

Thanks in advance!

1 Like

The confirmation link does api call to /api/auth/email-confirmation.
You can overwrite or create custom api to receive code and email from your confirmation page.

For changing to get small 6 digit code, you can follow this post.
https://forum.strapi.io/t/forgot-password-and-reset-password-6-digits-code/25947

1 Like