remix-auth-email-link provides a passwordless authentication strategy for Remix applications, leveraging 'magic links' sent via email. It is heavily inspired by the kcd strategy from Remix Auth v2. The library is actively maintained, with frequent patch and minor releases, and its current stable version is 2.1.1. A significant differentiator is its use of `crypto-js` instead of Node's built-in `crypto` module, enabling deployment on various serverless runtimes like Cloudflare Workers. It integrates with the `remix-auth` ecosystem and requires a custom `sendEmail` function to interface with any email service (e.g., Mailgun, SendGrid, AWS SES). This strategy streamlines user login by eliminating password management, offering a user-friendly and secure authentication flow.
npm install remix-auth-email-linkVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `EmailLinkStrategy` with `remix-auth`, including mock user management and email sending functions, and how to integrate it into Remix `loader` and `action` functions for login and magic link callbacks.
Ensure your `@remix-run/*` packages are at version `^2.0.0` or higher, and update `remix-auth-email-link` to `^2.0.0` or higher. Check your `package.json` and run `npm install` or `yarn install`.
Define `MAGIC_LINK_SECRET` in your environment variables (e.g., `.env` file for development, your hosting provider's configuration for production) with a long, random string. Example: `MAGIC_LINK_SECRET="your-super-secret-random-string"`.
Verify that the `callbackURL` string in your `EmailLinkStrategy` configuration (e.g., `/magic`) corresponds to the actual path of your Remix `loader` or `action` that handles the incoming magic link request.
Upgrade to `remix-auth-email-link@2.0.2` or newer, which ensures `http` is used as the protocol when running locally. Alternatively, ensure your local setup correctly handles `X-Forwarded-Proto` headers if using a proxy.
Set the `MAGIC_LINK_SECRET` environment variable in your development and production environments. For example, in a `.env` file: `MAGIC_LINK_SECRET="a_very_secure_random_string"`.
Ensure your Remix project and build setup are configured for ESM. If using TypeScript, check `tsconfig.json` for `"module": "esnext"` or `"module": "node16"`. If still encountering issues, verify that `remix.config.js` is correctly configured for your target environment (e.g., Cloudflare, Node).
Check the `successRedirect` and `failureRedirect` options passed to `authenticator.authenticate`. Ensure your `EmailLinkStrategy`'s `verify` callback correctly returns a user object or throws an error as expected. Also, confirm the `callbackURL` matches the actual route.