Skip to content

Instantly share code, notes, and snippets.

@n2o
Created July 28, 2025 13:16
Show Gist options
  • Save n2o/caef513a598cb355a9f1380813b5e5ef to your computer and use it in GitHub Desktop.
Save n2o/caef513a598cb355a9f1380813b5e5ef to your computer and use it in GitHub Desktop.
Strapi 5: Configure Email Reset Password Url via Environment Variables

As to my knowledge, strapi does not provide any options to set the email urls via the environment variable. So I included it into the strapi bootstrap function. It relies on the environment variable common.emails.resetPasswordUrl:

// index.ts
import type { Core } from "@strapi/strapi"

async function setEmailConfiguration(strapi: Core.Strapi) {
  strapi.log.info("✉️  Setting email configuration...")
  const resetPasswordUrl = strapi.config.get("common.emails.resetPasswordUrl")
  strapi.log.info(`✉️  Reset password Url: ${resetPasswordUrl}`)

  if (!resetPasswordUrl) {
    strapi.log.warn(
      "No reset password URL found. Maybe you need to add it in the strapi backend.",
    )
    return
  }

  const pluginStore = await strapi.store({
    type: "plugin",
    name: "users-permissions",
  })

  const advancedSettings = (await pluginStore.get({
    key: "advanced",
  })) as object

  await pluginStore.set({
    key: "advanced",
    value: {
      ...advancedSettings,
      email_reset_password: resetPasswordUrl,
    },
  })
}

// ...

export default {
  register({ strapi }: { strapi: Core.Strapi }) {
    strapi.log.info("Strapi registered for TypeScript usage 🎉")
  },

  bootstrap({ strapi }: { strapi: Core.Strapi }) {
    setEmailConfiguration(strapi)
  },
}

And that's how a config/common.ts configuration file could look like:

module.exports = ({ env }) => ({
  emails: {
    resetPasswordUrl: env("RESET_PASSWORD_URL"),
  },
})

I did not add it to the config/plugins.ts file, because to my knowledge I can't access the environment variables there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment