[PR #408] [MERGED] fix: magic links sent to unregistered emails when disabled sign up #11524

Closed
opened 2026-04-13 07:50:02 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/408
Author: @jslno
Created: 11/3/2024
Status: Merged
Merged: 11/5/2024
Merged by: @Bekacru

Base: mainHead: patch-1


📝 Commits (3)

  • 5d7db51 Fix magic links being sent to unregistered emails when disabled sign up
  • cca9706 Update index.ts
  • f251007 Update index.ts

📊 Changes

1 file changed (+11 additions, -0 deletions)

View changed files

📝 packages/better-auth/src/plugins/magic-link/index.ts (+11 -0)

📄 Description

As of right right now, we have to do something like this:

export const auth = betterAuth({
	// ...database
	plugins: [
		magicLink({
			disableSignUp: true,
			sendMagicLink: async (data: {
				email: string
				token: string
				url: string
			}) => {
				const isSignedUp =
					(await db.user.count({
						where: {
							email: data.email
						}
					})) > 0

				if (!isSignedUp) {
					throw new Error('User not found')
				}

				// ...send magic link to email
			}
		})
	]
})

but it brings some flaws with it. We are not able to provide an accurate error message to the client, because an INTERNAL_SERVER_ERROR is thrown.

With the commited adjustments an USER_NOT_FOUND error is thrown when a user isn't registered and disableSignUp is set to true. This allows us to provide a more detailed error message to the client.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/408 **Author:** [@jslno](https://github.com/jslno) **Created:** 11/3/2024 **Status:** ✅ Merged **Merged:** 11/5/2024 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `patch-1` --- ### 📝 Commits (3) - [`5d7db51`](https://github.com/better-auth/better-auth/commit/5d7db51ec147f5e181b667c2e94871bc73d5ae9f) Fix magic links being sent to unregistered emails when disabled sign up - [`cca9706`](https://github.com/better-auth/better-auth/commit/cca97063103225f851f9c61d26477b1c3a1c24a0) Update index.ts - [`f251007`](https://github.com/better-auth/better-auth/commit/f2510076f5eb93bddf9ff62488da1492477a6a36) Update index.ts ### 📊 Changes **1 file changed** (+11 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/magic-link/index.ts` (+11 -0) </details> ### 📄 Description As of right right now, we have to do something like this: ```ts export const auth = betterAuth({ // ...database plugins: [ magicLink({ disableSignUp: true, sendMagicLink: async (data: { email: string token: string url: string }) => { const isSignedUp = (await db.user.count({ where: { email: data.email } })) > 0 if (!isSignedUp) { throw new Error('User not found') } // ...send magic link to email } }) ] }) ``` but it brings some flaws with it. We are not able to provide an accurate error message to the client, because an `INTERNAL_SERVER_ERROR` is thrown. With the commited adjustments an `USER_NOT_FOUND` error is thrown when a user isn't registered and disableSignUp is set to true. This allows us to provide a more detailed error message to the client. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 07:50:02 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#11524