404 Error

auth-client;
import { createAuthClient } from "better-auth/react";
import { usernameClient } from "better-auth/client/plugins";
import { polarClient } from "@polar-sh/better-auth";

export const authClient = createAuthClient({
baseURL: process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000",
plugins: [polarClient(), usernameClient()],
});
import { createAuthClient } from "better-auth/react";
import { usernameClient } from "better-auth/client/plugins";
import { polarClient } from "@polar-sh/better-auth";

export const authClient = createAuthClient({
baseURL: process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000",
plugins: [polarClient(), usernameClient()],
});
auth.ts
...
export const auth = betterAuth({
secret: process.env.BETTER_AUTH_SECRET!,
baseURL: process.env.NEXT_PUBLIC_APP_URL!,
database: drizzleAdapter(db, {
provider: "sqlite",
}),
});
...
export const auth = betterAuth({
secret: process.env.BETTER_AUTH_SECRET!,
baseURL: process.env.NEXT_PUBLIC_APP_URL!,
database: drizzleAdapter(db, {
provider: "sqlite",
}),
});
... src\app\api\auth[...all]\route.ts
import { auth } from "@/lib/auth"; // path to your auth file
import { toNextJsHandler } from "better-auth/next-js";

export const { POST, GET } = toNextJsHandler(auth);
import { auth } from "@/lib/auth"; // path to your auth file
import { toNextJsHandler } from "better-auth/next-js";

export const { POST, GET } = toNextJsHandler(auth);
Changing the [...all]\route.ts to a simple hello world returns the expected response. It's only when using the toNextJsHandler that it returns a 404 for every api request. versions:
"better-auth": "^1.2.12",
"react": "^19.0.0",
"next": "15.3.5",
"better-auth": "^1.2.12",
"react": "^19.0.0",
"next": "15.3.5",
1 Reply
nikatune
nikatune2mo ago
can you send screenshot of console ?

Did you find this page helpful?