basePath does not work in Next.js

I move files form src/app/api/auth/[..all] to src/app/api/v1/auth/[..all] and I add basePath to betterAuth -> basePath: "/api/v1/auth" export const auth = betterAuth({ basePath:/api/v1/auth" database: drizzleAdapter(db, { provider: "pg" }), emailAndPassword: { enabled: true, autoSignIn: false }, }); when creating a new user i got this: POST /api/auth/sign-up/email?currentURL=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fnew 404 the request path does not change to api/auth/auth/...
4 Replies
bekacru
bekacru11mo ago
you need to change the path on the client as well
Ali Alnaghmoush
Ali AlnaghmoushOP11mo ago
I added it, but it does not work also export const authClient = createAuthClient({ baseURL: process.env.BETTER_AUTH_URL, basePath: "/api/v1/auth", }) I looked into createAuthClient and search "basePath" but I did not find it I use better-auth v0.8.2
bekacru
bekacru11mo ago
it doesn't accept basePath you should pas the base path with the base url
export const authClient = createAuthClient({
baseURL: `${process.env.BETTER_AUTH_URL}/api/v1/auth`,
})
export const authClient = createAuthClient({
baseURL: `${process.env.BETTER_AUTH_URL}/api/v1/auth`,
})
Ali Alnaghmoush
Ali AlnaghmoushOP11mo ago
I will try it It's working @bekacru thx! This how i'm setup: -- auth.ts export const auth = betterAuth({ basePath: process.env.BETTER_AUTH_BASE_PATH, database: drizzleAdapter(db, { provider: "pg" }), emailAndPassword: { enabled: true, autoSignIn: false }, }); -- auth-client.ts export const authClient = createAuthClient({ baseURL: process.env.BETTER_AUTH_URL_WITH_BASE_PATH, }) -- .env.local BETTER_AUTH_URL=http://localhost:3000 BETTER_AUTH_BASE_PATH=/api/v1/auth BETTER_AUTH_URL_WITH_BASE_PATH=${BETTER_AUTH_URL}/api/v1/auth

Did you find this page helpful?