Add verification link into custom-email-provider event object

Feature: Add verification link into custom-email-provider event object

Description: Currently there is no easy way to obtain a verification link (link to the user email verification or to the password reset page) from the email to use it inside the custom email provider script. To get it now developer needs to parse html attribute from event.notification object and just then include it into the API call.

Use-case: Custom email provider with own templates, which are triggered by API service with own business logic. API service should accept some information about the user and some dynamic parameters to use with email service. Adding a verification link will make it more convenient to make such API calls.

Just ran into this issue and used the stop-gap solution you mentioned. The following was my implementation:

  1. Modify the HTML of your email template to include an id attribute with the verification link as the value. I added it to the verification button:
<a
    id="{{url | escape}}"
    href="{{ url | escape }}"
    style="display:inline-block;background:#EB5424;color:white;font-family:'Avenir Next', Avenir, sans-serif;font-size:14px;font-weight:500;line-height:120%;margin:0;text-decoration:none;text-transform:none;padding:10px 25px;mso-padding-alt:0px;border-radius:3px;"
    target="_blank"
  >
    VERIFY YOUR ACCOUNT
</a>
  1. Parse the html in event.notification with RegEx
// Beware, this method will only work if the first id attribute in the HTML is the verification link.
const getVerificationLink = (html) => {
  const idRegex = /id\s*=\s*["']([^"']+)["']/;
  const match = html.match(idRegex);
  return match ? match[1] : '';
}

// Usage
getVerificationLink(event.notification.html)

Hope this helps someone

1 Like