[GH-ISSUE #8831] Magic link endpoint does not exist #28529

Closed
opened 2026-04-17 19:58:52 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @Lanhild on GitHub (Mar 29, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8831

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Install better-auth ^1.5.6 and configure the magicLink plugin.
  2. Attempt using the auth.signIn.magicLink function
  3. See the 404 error

Current vs. Expected behavior

The /sign-in/magic-link route does not seem to exist. It systematically returns a 404.

All other endpoints, such as /auth/ok or /auth/get-session work as expected.

What version of Better Auth are you using?

1.5.6

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#1 SMP PREEMPT_DYNAMIC Fri Mar 13 22:06:06 UTC 2026",
    "release": "6.19.8-200.fc43.x86_64",
    "cpuCount": 16,
    "cpuModel": "AMD Ryzen 7 9700X 8-Core Processor",
    "totalMemory": "62.40 GB",
    "freeMemory": "53.54 GB"
  },
  "node": {
    "version": "v24.14.1",
    "env": "development"
  },
  "packageManager": {
    "name": "pnpm",
    "version": "10.25.0"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "Unknown",
    "config": null
  }
}

Which area(s) are affected? (Select all that apply)

Backend, Client

Auth config (if applicable)

import { apiKey } from "@better-auth/api-key";
import db from "@repo/core-db";
import { env } from "@repo/core-env";
import { sendMagicLinkEmail } from "@repo/core-transactional/emails/MagicLinkEmail";
import { siteConfig } from "@repo/web-meta/constants";
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { magicLink, organization } from "better-auth/plugins";

import { apikeyHeader, apikeyPrefix } from "./constants";
import { databaseHooks } from "./hooks/databaseHooks";
import type { MagicLinkMetadata } from "./types";

export const auth = betterAuth({
  appName: siteConfig.name,
  baseURL: env.SERVER_URL,
  secret: env.AUTH_SECRET,
  trustedOrigins: [env.VITE_WEB_URL].map((url) => new URL(url).origin),
  database: prismaAdapter(db, {
    provider: "postgresql",
  }),
  databaseHooks,
  socialProviders: {
    github: {
      clientId: env.GITHUB_CLIENT_ID!,
      clientSecret: env.GITHUB_CLIENT_SECRET!,
    },
  },
  session: {
    expiresIn: env.AUTH_SESSION_MAX_AGE,
  },
  plugins: [
    apiKey({
      apiKeyHeaders: [apikeyHeader],
      defaultPrefix: apikeyPrefix,
      requireName: true,
      startingCharactersConfig: {
        charactersLength: 8,
      },
    }),
    magicLink({
      sendMagicLink: async ({ email, url, metadata }) => {
        const metaData = metadata as MagicLinkMetadata;

        console.log(JSON.stringify(metadata));

        await sendMagicLinkEmail({
          to: email,
          subject: metaData.subject,
          url,
          locale: metaData.locale,
        });
      },
    }),
    organization(),
  ],
  user: {
    additionalFields: {
      language: {
        type: "string",
        required: false,
      },
      theme: {
        type: "string",
        required: false,
      },
    },
  },
});

Additional context

I know it's not a CORS issue since my other auth endpoints work as expected.

Originally created by @Lanhild on GitHub (Mar 29, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8831 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Install better-auth ^1.5.6 and configure the `magicLink` plugin. 2. Attempt using the `auth.signIn.magicLink` function 3. See the 404 error ### Current vs. Expected behavior The `/sign-in/magic-link` route does not seem to exist. It systematically returns a 404. All other endpoints, such as `/auth/ok` or `/auth/get-session` work as expected. ### What version of Better Auth are you using? 1.5.6 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#1 SMP PREEMPT_DYNAMIC Fri Mar 13 22:06:06 UTC 2026", "release": "6.19.8-200.fc43.x86_64", "cpuCount": 16, "cpuModel": "AMD Ryzen 7 9700X 8-Core Processor", "totalMemory": "62.40 GB", "freeMemory": "53.54 GB" }, "node": { "version": "v24.14.1", "env": "development" }, "packageManager": { "name": "pnpm", "version": "10.25.0" }, "frameworks": null, "databases": null, "betterAuth": { "version": "Unknown", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend, Client ### Auth config (if applicable) ```typescript import { apiKey } from "@better-auth/api-key"; import db from "@repo/core-db"; import { env } from "@repo/core-env"; import { sendMagicLinkEmail } from "@repo/core-transactional/emails/MagicLinkEmail"; import { siteConfig } from "@repo/web-meta/constants"; import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { magicLink, organization } from "better-auth/plugins"; import { apikeyHeader, apikeyPrefix } from "./constants"; import { databaseHooks } from "./hooks/databaseHooks"; import type { MagicLinkMetadata } from "./types"; export const auth = betterAuth({ appName: siteConfig.name, baseURL: env.SERVER_URL, secret: env.AUTH_SECRET, trustedOrigins: [env.VITE_WEB_URL].map((url) => new URL(url).origin), database: prismaAdapter(db, { provider: "postgresql", }), databaseHooks, socialProviders: { github: { clientId: env.GITHUB_CLIENT_ID!, clientSecret: env.GITHUB_CLIENT_SECRET!, }, }, session: { expiresIn: env.AUTH_SESSION_MAX_AGE, }, plugins: [ apiKey({ apiKeyHeaders: [apikeyHeader], defaultPrefix: apikeyPrefix, requireName: true, startingCharactersConfig: { charactersLength: 8, }, }), magicLink({ sendMagicLink: async ({ email, url, metadata }) => { const metaData = metadata as MagicLinkMetadata; console.log(JSON.stringify(metadata)); await sendMagicLinkEmail({ to: email, subject: metaData.subject, url, locale: metaData.locale, }); }, }), organization(), ], user: { additionalFields: { language: { type: "string", required: false, }, theme: { type: "string", required: false, }, }, }, }); ``` ### Additional context I know it's not a CORS issue since my other auth endpoints work as expected.
GiteaMirror added the lockedbug labels 2026-04-17 19:58:52 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 29, 2026):

This is likely caused by missing the client-side plugin configuration. The magic link plugin requires configuration on both server and client sides.

Add magicLinkClient() to your client auth configuration [1]:

import { createAuthClient } from "better-auth/client";
import { magicLinkClient } from "better-auth/client/plugins";

export const authClient = createAuthClient({
  plugins: [magicLinkClient()],
});

Without the client plugin, auth.signIn.magicLink won't know how to properly route to the server endpoint.

Additionally, note that v1.5.6 has a known bug affecting magic link verification when using usePlural: true in the database adapter configuration [2]. If you're using that setting, you may encounter issues during the verification step as well.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:4151083529 --> @dosubot[bot] commented on GitHub (Mar 29, 2026): <!-- Answer --> This is likely caused by **missing the client-side plugin configuration**. The magic link plugin requires configuration on both server and client sides. Add `magicLinkClient()` to your client auth configuration [[1]](https://github.com/better-auth/better-auth/blob/03d2df66030ba7c020024d3fb4147a5cf9650192/packages/better-auth/src/plugins/magic-link/client.ts#L4-L9): ```typescript import { createAuthClient } from "better-auth/client"; import { magicLinkClient } from "better-auth/client/plugins"; export const authClient = createAuthClient({ plugins: [magicLinkClient()], }); ``` Without the client plugin, `auth.signIn.magicLink` won't know how to properly route to the server endpoint. Additionally, note that v1.5.6 has a known bug affecting magic link verification when using `usePlural: true` in the database adapter configuration [[2]](https://github.com/better-auth/better-auth/issues/8228#issuecomment-3979775985). If you're using that setting, you may encounter issues during the verification step as well. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/bae0aaf1-7ab2-4056-9524-d04a441a1280?feedback_type=great_response&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/bae0aaf1-7ab2-4056-9524-d04a441a1280?feedback_type=irrelevant_answer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/bae0aaf1-7ab2-4056-9524-d04a441a1280?feedback_type=incorrect_sources&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/bae0aaf1-7ab2-4056-9524-d04a441a1280?feedback_type=too_verbose&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/bae0aaf1-7ab2-4056-9524-d04a441a1280?feedback_type=hallucination&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/bae0aaf1-7ab2-4056-9524-d04a441a1280?feedback_type=bug_report&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report) | [Other](https://app.dosu.dev/response-feedback/bae0aaf1-7ab2-4056-9524-d04a441a1280?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20likely%20caused%20by%20%2A%2Amissing%20the%20client-side%20plugin%20configuration%2A%2A.%20The%20magic%20link%20plugin%20requires%20configuration%20on%20both%20server%20and%20client%20sides.%0A%0AAdd%20%60magicLinkClient%28%29%60%20to%20your%20client%20auth%20configuration%20%5B%5B1%5D%5D%28https%3A//github.com/better-auth/better-auth/blob/03d2df66030ba7c020024d3fb4147a5cf9650192/packages/better-auth/src/plugins/magic-link/client.ts%23L4-L9%29%3A%0A%0A%60%60%60typescript%0Aimport%20%7B%20createAuthClient%20%7D%20from%20%22better-auth/client%22%3B%0Aimport%20%7B%20magicLinkClient%20%7D%20from%20%22better-auth/client/plugins%22%3B%0A%0Aexport%20const%20authClient%20%3D%20createAuthClient%28%7B%0A%20%20plugins%3A%20%5BmagicLinkClient%28%29%5D%2C%0A%7D%29%3B%0A%60%60%60%0A%0AWithout%20the%20client%20plugin%2C%20%60auth.signIn.magicLink%60%20won%27t%20know%20how%20to%20properly%20route%20to%20the%20server%20endpoint.%0A%0AAdditionally%2C%20note%20that%20v1.5.6%20has%20a%20known%20bug%20affecting%20magic%20link%20verification%20when%20using%20%60usePlural%3A%20true%60%20in%20the%20database%20adapter%20configuration%20%5B%5B2%5D%5D%28https%3A//github.com/better-auth/better-auth/issues/8228%23issuecomment-3979775985%29.%20If%20you%27re%20using%20that%20setting%2C%20you%20may%20encounter%20issues%20during%20the%20verification%20step%20as%20well.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/8831)
Author
Owner

@Lanhild commented on GitHub (Mar 29, 2026):

It is configured in the client.

export const authClient = createAuthClient({
  baseURL: env.VITE_SERVER_URL,
  plugins: [apiKeyClient(), magicLinkClient(), organizationClient()],
});
<!-- gh-comment-id:4151091449 --> @Lanhild commented on GitHub (Mar 29, 2026): It is configured in the client. ``` export const authClient = createAuthClient({ baseURL: env.VITE_SERVER_URL, plugins: [apiKeyClient(), magicLinkClient(), organizationClient()], }); ```
Author
Owner

@Lanhild commented on GitHub (Mar 29, 2026):

The catch-all route was incorrectly configured in my express server.

<!-- gh-comment-id:4151112581 --> @Lanhild commented on GitHub (Mar 29, 2026): The catch-all route was incorrectly configured in my express server.
Author
Owner

@github-actions[bot] commented on GitHub (Apr 6, 2026):

This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.

<!-- gh-comment-id:4189793786 --> @github-actions[bot] commented on GitHub (Apr 6, 2026): This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#28529