Skip to content

[BUG] Expo Authorization Proxy returns 400 instead of redirect when deployed on Cloudflare via opennextjs-cloudflare #1037

@imalec-huang

Description

@imalec-huang

Describe the bug

Hi, thanks for this project!

I’m deploying a Next.js 15 + better-auth + expo project using @opennextjs/cloudflare. Everything works fine when accessing /api/auth/... from a web client, including login/logout/check.

However, when using Expo together with better-auth/expo-plugin, Expo tries to request:

/api/auth/expo-authorization-proxy?authorizationURL=...

and Cloudflare always returns:

{
"code": "UNEXPECTED_ERROR",
"message": "Unexpected error"
}

instead of the expected 302 redirect.

What I tested

❌ production (Cloudflare)
fails with 400

❌localhost run command: opennextjs-cloudflare preview
same behavior as production (400)

✅ next dev
works perfectly (302 redirect)

This means the issue only happens on the Cloudflare adapter runtime, not in Next.js dev or better-auth itself.

Expected behavior

/api/auth/expo-authorization-proxy should perform a redirect (302), same as in development.

Actual behavior

400 Unexpected Error inside Cloudflare runtime

Versions

"@opennextjs/cloudflare": "^1.14.4"
"next": "15.5.7"
"better-auth": "^1.4.5"

Extra note

This only happens with Expo authorization plugin integration. Other authentication routes behave normally.

Thanks! (The redirect ghosts seem to vanish only in dev mode 😅)

Steps to reproduce

Image Image

Expected behavior

Image

@opennextjs/cloudflare version

1.14.4

Wrangler version

4.53.0

next info output

pnpm next info
npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm.
npm warn Unknown env config "verify-deps-before-run". This will stop working in the next major version of npm.
This project is configured to use pnpm because /Users/imalec/workspaces/resolvai/resolvai-auth/package.json has a "packageManager" field
This project is configured to use pnpm because /Users/imalec/workspaces/resolvai/resolvai-auth/package.json has a "packageManager" field

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.1.0: Mon Oct 20 19:34:05 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6041
  Available memory (MB): 65536
  Available CPU cores: 14
Binaries:
  Node: 22.17.0
  npm: 11.6.0
  Yarn: N/A
  pnpm: 10.25.0
Relevant Packages:
  next: 15.5.7 // An outdated version detected (latest is 16.0.8), upgrade is highly recommended!
  eslint-config-next: 15.5.4
  react: 19.2.1
  react-dom: 19.2.1
  typescript: 5.9.3
Next.js Config:
  output: standalone
 ⚠ An outdated version detected (latest is 16.0.8), upgrade is highly recommended!
   Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
   Read more - https://nextjs.org/docs/messages/opening-an-issue

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions