[GH-ISSUE #3684] Thought issue fixed but still getting 405s for POST events #27009

Closed
opened 2026-04-17 17:47:32 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @weisisheng on GitHub (Jul 29, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3684

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Using a simple (or modified) api/auth/[...all]/route.ts, keep getting #405 errors when trying social providers or email/password.

Current vs. Expected behavior

Try to log in to app and getting #405s with error re: to POST events.

Use the standard api route from the docs. Also separated out methods per some suggestions of next.js bug:

import { auth } from '@/lib/auth/auth';
import { toNextJsHandler } from 'better-auth/next-js';

const handlers = toNextJsHandler(auth);

// Debug logging to see what handlers are available
console.log('Available handlers:', Object.keys(handlers));
console.log('GET handler exists:', typeof handlers.GET);
console.log('POST handler exists:', typeof handlers.POST);

export const GET = handlers.GET;
export const POST = handlers.POST;

These are the experiments

  Try these exact endpoints:
  # Email Sign Up (what you've been testing - correct)
  curl -X POST http://localhost:3000/api/auth/sign-up/email \
    -H "Content-Type: application/json" \
    -d '{"email":"test@example.com","password":"testpass123","name":"Test User"}'

  # Email Sign In
  curl -X POST http://localhost:3000/api/auth/sign-in/email \
    -H "Content-Type: application/json" \
    -d '{"email":"test@example.com","password":"testpass123"}'

  # Sign Out  
  curl -X POST http://localhost:3000/api/auth/sign-out \
    -H "Content-Type: application/json" \
    -d '{}'

  You've been testing the correct endpoints - the issue is that Better Auth isn't registering the POST handlers for email/password authentication, only the GET handlers for
   basic session management.

> "method not allowed" on all 3 endpoints

Thanks in advance!

What version of Better Auth are you using?

1.3.x

Provide environment information

- Ubuntu 24.04, Next.js 15.x (latest), Chrome / Firefox (latest), Node 21.x

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

Client

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @weisisheng on GitHub (Jul 29, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3684 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Using a simple (or modified) api/auth/[...all]/route.ts, keep getting #405 errors when trying social providers or email/password. ### Current vs. Expected behavior Try to log in to app and getting #405s with error re: to POST events. Use the standard api route from the docs. Also separated out methods per some suggestions of next.js bug: ``` import { auth } from '@/lib/auth/auth'; import { toNextJsHandler } from 'better-auth/next-js'; const handlers = toNextJsHandler(auth); // Debug logging to see what handlers are available console.log('Available handlers:', Object.keys(handlers)); console.log('GET handler exists:', typeof handlers.GET); console.log('POST handler exists:', typeof handlers.POST); export const GET = handlers.GET; export const POST = handlers.POST; ``` ### These are the experiments ``` Try these exact endpoints: # Email Sign Up (what you've been testing - correct) curl -X POST http://localhost:3000/api/auth/sign-up/email \ -H "Content-Type: application/json" \ -d '{"email":"test@example.com","password":"testpass123","name":"Test User"}' # Email Sign In curl -X POST http://localhost:3000/api/auth/sign-in/email \ -H "Content-Type: application/json" \ -d '{"email":"test@example.com","password":"testpass123"}' # Sign Out curl -X POST http://localhost:3000/api/auth/sign-out \ -H "Content-Type: application/json" \ -d '{}' You've been testing the correct endpoints - the issue is that Better Auth isn't registering the POST handlers for email/password authentication, only the GET handlers for basic session management. > "method not allowed" on all 3 endpoints ``` Thanks in advance! ### What version of Better Auth are you using? 1.3.x ### Provide environment information ```bash - Ubuntu 24.04, Next.js 15.x (latest), Chrome / Firefox (latest), Node 21.x ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-17 17:47:32 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 29, 2025):

The 405 errors for POST requests are not caused by missing POST handlers in Better Auth—those are always registered if your config enables them. The most common causes are route file structure, export pattern, or configuration issues in your Next.js setup.

Make sure your route file is at app/api/auth/[...all]/route.ts and uses the exact export pattern from the official demo:

import { auth } from "@/lib/auth";
import { toNextJsHandler } from "better-auth/next-js";

export const { GET, POST } = toNextJsHandler(auth);

Avoid assigning to a handlers variable first—export GET and POST directly as shown above [demo example].

Check that your baseURL and basePath are set and consistent in both your server-side (betterAuth) and client-side (createAuthClient) configs. Mismatches here can cause endpoints to not be recognized or return 405/404 errors [baseURL config guidance].

If you’re statically importing your auth module, try switching to a dynamic import in your route file to avoid build-time evaluation issues:

const mod = await import('@/lib/auth/auth');
export const { GET, POST } = toNextJsHandler(mod.auth);

[dynamic import advice]

Clear your .next build cache and restart your dev server after making these changes. If the problem persists, temporarily replace your route file with the official demo code to isolate the issue. Also, check for any conflicting routes or files that could shadow your intended API route.

These steps should resolve the 405 errors if the issue is with your Next.js project structure or config.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3130410892 --> @dosubot[bot] commented on GitHub (Jul 29, 2025): <!-- Answer --> The 405 errors for POST requests are not caused by missing POST handlers in Better Auth—those are always registered if your config enables them. The most common causes are route file structure, export pattern, or configuration issues in your Next.js setup. Make sure your route file is at `app/api/auth/[...all]/route.ts` and uses the exact export pattern from the official demo: ```ts import { auth } from "@/lib/auth"; import { toNextJsHandler } from "better-auth/next-js"; export const { GET, POST } = toNextJsHandler(auth); ``` Avoid assigning to a `handlers` variable first—export GET and POST directly as shown above [[demo example]](https://github.com/better-auth/better-auth/blob/ed574aa2fbd21c1b9e28d4554993067b159a568b/demo/nextjs/app/api/auth/[...all]/route.ts). Check that your `baseURL` and `basePath` are set and consistent in both your server-side (`betterAuth`) and client-side (`createAuthClient`) configs. Mismatches here can cause endpoints to not be recognized or return 405/404 errors [[baseURL config guidance]](https://github.com/better-auth/better-auth/issues/2710). If you’re statically importing your auth module, try switching to a dynamic import in your route file to avoid build-time evaluation issues: ```ts const mod = await import('@/lib/auth/auth'); export const { GET, POST } = toNextJsHandler(mod.auth); ``` [[dynamic import advice]](https://github.com/better-auth/better-auth/issues/3346) Clear your `.next` build cache and restart your dev server after making these changes. If the problem persists, temporarily replace your route file with the official demo code to isolate the issue. Also, check for any conflicting routes or files that could shadow your intended API route. These steps should resolve the 405 errors if the issue is with your Next.js project structure or config. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/a954a229-3d2e-41a5-bbb3-21c68d0f8bd9?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/a954a229-3d2e-41a5-bbb3-21c68d0f8bd9?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/a954a229-3d2e-41a5-bbb3-21c68d0f8bd9?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/a954a229-3d2e-41a5-bbb3-21c68d0f8bd9?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/a954a229-3d2e-41a5-bbb3-21c68d0f8bd9?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/a954a229-3d2e-41a5-bbb3-21c68d0f8bd9?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/a954a229-3d2e-41a5-bbb3-21c68d0f8bd9?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&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/3684)
Author
Owner

@weisisheng commented on GitHub (Jul 29, 2025):

Hmm, trying the demo on its own works for me but not the tips on my original app. Getting CORS errors along with the 405s. Will need to review line-by-line. Thanks,

<!-- gh-comment-id:3131666353 --> @weisisheng commented on GitHub (Jul 29, 2025): Hmm, trying the demo on its own works for me but not the tips on my original app. Getting CORS errors along with the 405s. Will need to review line-by-line. Thanks,
Author
Owner

@weisisheng commented on GitHub (Jul 30, 2025):

Not sure what it was but rebuilding everything works. Thanks for the terrific details.

<!-- gh-comment-id:3134875501 --> @weisisheng commented on GitHub (Jul 30, 2025): Not sure what it was but rebuilding everything works. Thanks for the terrific details.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27009