[GH-ISSUE #510] 405 when reaching /api/auth/... when hosted on vercel. Work locally #8300

Closed
opened 2026-04-13 03:22:24 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @romainchkr on GitHub (Nov 12, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/510

Describe the bug
I set up better-auth in a nextjs project. Everything work locally. However as soon as its hosted on vercel each time i call signIn or any auth method from the better auth client it return a 405 (Method not allowed) response.
Each time the /api/auth/x is called it return a 405.

The baseUrl is well set in the environment variables as well as the secret.

i'm turning my head around trying to fix it. Have you ever seen that ?

Expected behavior
The auth methods client side works

Originally created by @romainchkr on GitHub (Nov 12, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/510 **Describe the bug** I set up better-auth in a nextjs project. Everything work locally. However as soon as its hosted on vercel each time i call signIn or any auth method from the better auth client it return a 405 (Method not allowed) response. Each time the /api/auth/x is called it return a 405. The baseUrl is well set in the environment variables as well as the secret. i'm turning my head around trying to fix it. Have you ever seen that ? **Expected behavior** The auth methods client side works
GiteaMirror added the locked label 2026-04-13 03:22:24 -05:00
Author
Owner

@romainchkr commented on GitHub (Nov 18, 2024):

Everything works perfectlty when hosting elswhere like netlify. I have no clue why vercel is always giving me a 405 (Method not allowed) when trying an endpoint of the better-auth server.

<!-- gh-comment-id:2484295494 --> @romainchkr commented on GitHub (Nov 18, 2024): Everything works perfectlty when hosting elswhere like netlify. I have no clue why vercel is always giving me a 405 (Method not allowed) when trying an endpoint of the better-auth server.
Author
Owner

@bleevv commented on GitHub (Dec 4, 2024):

Hi, I encountered the same issue and resolved it through the following solution. You just need to add the code below to your next.config.ts:

webpack: (config) => {
    config.externals.push({
      'utf-8-validate': 'commonjs utf-8-validate',
      bufferutil: 'commonjs bufferutil',
    })
    return config
  },
<!-- gh-comment-id:2516214395 --> @bleevv commented on GitHub (Dec 4, 2024): Hi, I encountered the same issue and resolved it through the following solution. You just need to add the code below to your next.config.ts: ```javascript webpack: (config) => { config.externals.push({ 'utf-8-validate': 'commonjs utf-8-validate', bufferutil: 'commonjs bufferutil', }) return config }, ```
Author
Owner

@romainchkr commented on GitHub (Dec 4, 2024):

Hi !
Unfortunately it doesn't solve the problem on my side :(
Did you manage to debug/log some infos on the vercel side calling signin method and reaching endpoint /api/auth/x ? Because i don't even have logs on vercel side when calling better auth signin (i just got the error in the network tab/console tab of the browser).
However my other api routes works perfectly and show logs

And ofc everything works fine hosting somewhere else 🥲

<!-- gh-comment-id:2516592083 --> @romainchkr commented on GitHub (Dec 4, 2024): Hi ! Unfortunately it doesn't solve the problem on my side :( Did you manage to debug/log some infos on the vercel side calling signin method and reaching endpoint /api/auth/x ? Because i don't even have logs on vercel side when calling better auth signin (i just got the error in the network tab/console tab of the browser). However my other api routes works perfectly and show logs And ofc everything works fine hosting somewhere else 🥲
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8300