Issue trying to convert to cloudflare workers
I have my project currently deployed on vercel as a NextJs project. I'm trying to convert it to cloudflare workers using opennextjs/cloudflare, however I'm encountering some issues with the auth handler.
and my current auth setup:
/api/auth/get-session - Exception Thrown @ 4/5/2025, 9:35:09 PM
✘ [ERROR] Error: The script will never generate a response.
✘ [ERROR] Error: Promise will never complete./api/auth/get-session - Exception Thrown @ 4/5/2025, 9:35:09 PM
✘ [ERROR] Error: The script will never generate a response.
✘ [ERROR] Error: Promise will never complete.and my current auth setup:
export function getAuth() {
const db = getDB();
return betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
}),
trustedOrigins: [env.NEXT_PUBLIC_BETTER_AUTH_URL],
plugins: [
username(),
nextCookies(),
],
secret: env.BETTER_AUTH_SECRET,
baseURL: env.NEXT_PUBLIC_BETTER_AUTH_URL,
emailAndPassword: {
enabled: true,
},
});
}export function getAuth() {
const db = getDB();
return betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
}),
trustedOrigins: [env.NEXT_PUBLIC_BETTER_AUTH_URL],
plugins: [
username(),
nextCookies(),
],
secret: env.BETTER_AUTH_SECRET,
baseURL: env.NEXT_PUBLIC_BETTER_AUTH_URL,
emailAndPassword: {
enabled: true,
},
});
}// /api/auth/[...all]/route.ts (tried this way to instantiate db every request, didn't work)
export async function POST(req: NextRequest) {
const auth = getAuth();
const authHandler = toNextJsHandler(auth);
return authHandler.POST(req);
}
export async function GET(req: NextRequest) {
const auth = getAuth();
const authHandler = toNextJsHandler(auth);
return authHandler.GET(req);
}// /api/auth/[...all]/route.ts (tried this way to instantiate db every request, didn't work)
export async function POST(req: NextRequest) {
const auth = getAuth();
const authHandler = toNextJsHandler(auth);
return authHandler.POST(req);
}
export async function GET(req: NextRequest) {
const auth = getAuth();
const authHandler = toNextJsHandler(auth);
return authHandler.GET(req);
}