Skip to content

Cloudflare: Error: The script will never generate a response. #969

@CMMA04

Description

@CMMA04

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Deploy or preview an aplication using Cloudlflare Pages or Workers, the issue does not show up if you use dev
  2. Try to sign in

Current vs. Expected behavior

Current:
Sign in, shows the following error in terminal:

✘ [ERROR] A hanging Promise was canceled. This happens when the worker runtime is waiting for a Promise from JavaScript to resolve, but has detected that the Promise cannot possibly ever resolve because all code and events related to the Promise's I/O context have already finished.


[wrangler:inf] POST /api/auth/sign-in/email 500 Internal Server Error (296ms)
✘ [ERROR] Uncaught (in response) Error: The script will never generate a response.

If you try again, it works.
It does not get catch by a try statement, however if you read the error value using:

const { data, error } = await authClient.signIn.email({
      email: event.data.email,
      password: event.data.password,
});
if (error) {
      console.log(error)
} 

It will say: undefined

Expected:
Sign in without issues

What version of Better Auth are you using?

1.0.22

Provide environment information

- OS: MacOS y Windows (tested using preview) and Cloudflare Pages
- Browser: Any
- Framework: Nuxt

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

Backend

Auth config (if applicable)

export const auth = betterAuth({
  appName: "test",
  database: drizzleAdapter(db, {
    provider: "pg",
    schema: {
      ...schema,
    },
  }),
  secondaryStorage: {
    get: async (key) => await redis.get(key),
    set: async (key, value, ttl) => {
      if (ttl) await redis.set(key, JSON.stringify(value), { ex: ttl });
      else await redis.set(key, JSON.stringify(value));
    },
    delete: async (key) => {
      await redis.del(key);
    },
  },
  plugins: [
    openAPI(),
  ],
  emailAndPassword: {
    enabled: true,
  },
  emailVerification: {
    sendVerificationEmail: async ({ user, url, token }) => {
      const resend = new Resend(process.env.RESEND_API_KEY);
      const data = await resend.emails.send({
        from: "[email protected]",
        to: user.email,
        subject: "Email verification",
        html: `Confirmation link: ${url}`,
      });
    },
  },
});

Additional context

For some reason it does not happen if you run under nuxt dev, so it is a Clouflare only issue

I apologize if it is a issue in our side or a known issue, I am learning to use this library and i am still new to auth enviorement

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglockedLocked conversations after being closed for 7 days

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions