[GH-ISSUE #1309] Edge runtime gives a MessageChannel not found error. #17317

Closed
opened 2026-04-15 15:25:42 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @xharauenea on GitHub (Jan 30, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1309

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

This happens if you force the endpoint api/auth/[...all]/route.ts to have a runtime of 'edge'

export const runtime = 'edge';

In Next.js 15.0.2.

Current vs. Expected behavior

I expect this auth to work on edge as well. No reason not to.

What version of Better Auth are you using?

1.0.4

Provide environment information

- OS: MacOs Sonoma

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

Backend, Package

Auth config (if applicable)

{
  secret: env.BETTER_AUTH_SECRET,
  secondaryStorage: {
    get: async (key) => {
      const value = await kv.get(key);
      if (!value) return null;
      return JSON.stringify(value);
    },
    set: async (key, value, ttl) => {
      if (ttl) await kv.set(key, value, { ex: ttl });
      else await kv.set(key, value);
    },
    delete: async (key) => {
      await kv.del(key);
    },
  },
  database: drizzleAdapter(db, {
    schema: {
      user: schema.User,
      session: schema.Session,
      account: schema.Account,
      verification: schema.Verification,
      rateLimit: schema.RateLimit,
      organization: schema.Organization,
      member: schema.Member,
      invitation: schema.Invitation,
    },
    provider: "pg",
  }),
  emailAndPassword: {
    enabled: true,
    autoSignIn: true,
    requireEmailVerification: false,
  },
  emailVerification: {
    autoSignInAfterVerification: true,
    expiresIn: 60 * 60 * 24 * 7, // 7 days
    sendOnSignUp: true,
    async sendVerificationEmail(data, request) {
      await fetch(
        `${baseURL(request?.headers.get("host"))}/api/verify-email/send`,
        {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            from:
              env.VERCEL_ENV === "development"
                ? "evelyn.ernser65@ethereal.email"
                : "bilkado@invitations.bilkado.com",
            to: data.user.email,
            subject: "Verify your email address - Bilkado",
            html: await render(
              VercelVerifyEmail({
                email: data.user.email,
                name: data.user.name,
                url: `${baseURL(request?.headers.get("host"))}/api/verify-email/accept/${data.token}`,
              }),
            ),
          }),
        },
      ).catch((err) => {
        console.log(err);
      });
    },
  },
  advanced: {
    generateId: false,
  },
  rateLimit: {
    window: 10, // time window in seconds
    max: 10, // max requests in the window
    storage: "secondary-storage",
    enabled: true,
  },
  session: {
    cookieCache: {
      enabled: true,
      maxAge: 30, // Cache duration in seconds
    },
  },
  logger: {
    disabled: false,
  },
  plugins: [
    organization({
      async sendInvitationEmail(data, request) {
        await fetch(
          `${baseURL(request?.headers.get("host"))}/api/invitation/send`,
          {
            method: "POST",
            headers: {
              "Content-Type": "application/json",
            },
            body: JSON.stringify({
              from:
                env.VERCEL_ENV === "development"
                  ? "evelyn.ernser65@ethereal.email"
                  : "bilkado@invitations.bilkado.com",
              to: data.email,
              subject: `Invitation to join - ${data.organization.name} on Bilkado`,
              html: await render(
                VercelInviteUserEmail({
                  invitedByEmail: data.inviter.user.email,
                  invitedByUsername: data.inviter.user.name,
                  teamName: data.organization.name,
                  teamImage: data.organization.logo ?? "",
                  inviteLink: `${baseURL(request?.headers.get("host"))}/api/invitation/accept/${data.id}`,
                }),
              ),
            }),
          },
        ).catch((err) => {
          console.log(err);
        });
      },
    }),
  ],
}

Additional context

Is it possible in the future you will be able to support edge runtime, especially on vercel.

Originally created by @xharauenea on GitHub (Jan 30, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1309 ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce This happens if you force the endpoint api/auth/[...all]/route.ts to have a runtime of 'edge' ```ts export const runtime = 'edge'; ``` In Next.js 15.0.2. ### Current vs. Expected behavior I expect this auth to work on edge as well. No reason not to. ### What version of Better Auth are you using? 1.0.4 ### Provide environment information ```bash - OS: MacOs Sonoma ``` ### Which area(s) are affected? (Select all that apply) Backend, Package ### Auth config (if applicable) ```typescript { secret: env.BETTER_AUTH_SECRET, secondaryStorage: { get: async (key) => { const value = await kv.get(key); if (!value) return null; return JSON.stringify(value); }, set: async (key, value, ttl) => { if (ttl) await kv.set(key, value, { ex: ttl }); else await kv.set(key, value); }, delete: async (key) => { await kv.del(key); }, }, database: drizzleAdapter(db, { schema: { user: schema.User, session: schema.Session, account: schema.Account, verification: schema.Verification, rateLimit: schema.RateLimit, organization: schema.Organization, member: schema.Member, invitation: schema.Invitation, }, provider: "pg", }), emailAndPassword: { enabled: true, autoSignIn: true, requireEmailVerification: false, }, emailVerification: { autoSignInAfterVerification: true, expiresIn: 60 * 60 * 24 * 7, // 7 days sendOnSignUp: true, async sendVerificationEmail(data, request) { await fetch( `${baseURL(request?.headers.get("host"))}/api/verify-email/send`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ from: env.VERCEL_ENV === "development" ? "evelyn.ernser65@ethereal.email" : "bilkado@invitations.bilkado.com", to: data.user.email, subject: "Verify your email address - Bilkado", html: await render( VercelVerifyEmail({ email: data.user.email, name: data.user.name, url: `${baseURL(request?.headers.get("host"))}/api/verify-email/accept/${data.token}`, }), ), }), }, ).catch((err) => { console.log(err); }); }, }, advanced: { generateId: false, }, rateLimit: { window: 10, // time window in seconds max: 10, // max requests in the window storage: "secondary-storage", enabled: true, }, session: { cookieCache: { enabled: true, maxAge: 30, // Cache duration in seconds }, }, logger: { disabled: false, }, plugins: [ organization({ async sendInvitationEmail(data, request) { await fetch( `${baseURL(request?.headers.get("host"))}/api/invitation/send`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ from: env.VERCEL_ENV === "development" ? "evelyn.ernser65@ethereal.email" : "bilkado@invitations.bilkado.com", to: data.email, subject: `Invitation to join - ${data.organization.name} on Bilkado`, html: await render( VercelInviteUserEmail({ invitedByEmail: data.inviter.user.email, invitedByUsername: data.inviter.user.name, teamName: data.organization.name, teamImage: data.organization.logo ?? "", inviteLink: `${baseURL(request?.headers.get("host"))}/api/invitation/accept/${data.id}`, }), ), }), }, ).catch((err) => { console.log(err); }); }, }), ], } ``` ### Additional context Is it possible in the future you will be able to support edge runtime, especially on vercel.
GiteaMirror added the lockedbug labels 2026-04-15 15:25:42 -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#17317