Skip to main content

Password Reset

Password reset is one of the things you encounter with when building authentication if not using Auth0 or Cognito services.

import { Notifire, ChannelTypeEnum } from "@notifire/core";import { SendgridEmailProvider } from "@notifire/sendgrid";import { TwilioSmsProvider } from "@notifire/twilio";
const notifire = new Notifire();
await notifire.registerProvider(  new TwilioSmsProvider({    accountSid: process.env.TWILIO_ACCOUNT_SID,    authToken: process.env.TWILIO_AUTH_TOKEN,    from: process.env.TWILIO_FROM_NUMBER,  }));
await notifire.registerProvider(  new SendgridEmailProvider({    apiKey: process.env.SENDGRID_API_KEY,  }));
// Defined in a file or folder responsible for managing templatesconst passwordResetTemplate = await notifire.registerTemplate({  id: "password-reset-request",  messages: [    {      subject: "Your password reset request for {{appName}}",      channel: ChannelTypeEnum.EMAIL,      template: `          Hi {{firstName}}!
          To reset your password click <a href="{{resetLink}}">here.</a>      `,    },    {      channel: ChannelTypeEnum.SMS,      template: `Your password reset request for {{appName}}. To reset your password click {{resetLink}}`,      active: (data) => !data.$email,    },  ],});
// Triggered in the relevant part of the business logic of your codeawait notifire.trigger("password-reset-request", {  $user_id: "<USER IDENTIFIER>",  $email: "<USER EMAIL>",  firstName: "John",  lastName: "Doe",  resetLink: "",  appName: "My App",});