Next.js build failing

app/api/auth/[...all]/route.ts
Type error: Route "app/api/auth/[...all]/route.ts" has an invalid export:
"unknown" is not a valid GET return type:
Expected "void | Response | Promise<void | Response>", got "unknown".

Next.js build worker exited with code: 1 and signal: null
app/api/auth/[...all]/route.ts
Type error: Route "app/api/auth/[...all]/route.ts" has an invalid export:
"unknown" is not a valid GET return type:
Expected "void | Response | Promise<void | Response>", got "unknown".

Next.js build worker exited with code: 1 and signal: null
import { auth } from "@/lib/auth/server";
import { toNextJsHandler } from "better-auth/next-js";

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

export const { GET, POST } = toNextJsHandler(auth);
Does anyone know what this may be or how to fix it?
Solution:
This ended up being I just needed to delete my node_modules
Jump to solution
9 Replies
nikatune
nikatune4mo ago
which version? next js and better auth
SNiKerDoDle
SNiKerDoDleOP4mo ago
15.3.5 nextjs and better auth 1.2.12 I'm on the path of a change someone made to the better-auth config unnecessarily, but open to ideas if you have any... didn't appear to be the case on what I thought it may be @nikatune
nikatune
nikatune4mo ago
can you send your auth config?
SNiKerDoDle
SNiKerDoDleOP4mo ago
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "mysql",
}),
secret: process.env.BETTER_AUTH_SECRET || "fallback-secret-for-development",
baseURL: process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000",
emailAndPassword: {
enabled: true,
async sendResetPassword(data, request) {
// Send password reset email using our email service
try {
const resetUrl = `${process.env.NEXT_PUBLIC_APP_URL}/reset-password?token=${data.token}`;

const result = await emailService.sendPasswordResetEmail(
...
);

if (!result.success) {
console.error("Failed to send password reset email:", result.error);
throw new Error("Failed to send password reset email");
}

console.log(
"Password reset email sent successfully:",
result.messageId
);
} catch (error) {
console.error("Error sending password reset email:", error);
throw error;
}
},
},
plugins: [
customSession(async ({ user, session }) => {
type RoleType = keyof typeof roles;
return {
user: {
...user,
role: (user as any).role as RoleType,
},
session,
};
}),
magicLink({
sendMagicLink: async ({ email, url }) => {
const result = await emailService.sendMagicLinkEmail(
{ email },
{
magicLink: url,
appName: process.env.NEXT_PUBLIC_APP_NAME || "Your App",
appUrl: process.env.NEXT_PUBLIC_APP_URL || "https://yourapp.com",
}
);
if (!result.success) {
console.error("Failed to send magic link email:", result.error);
throw new Error("Failed to send magic link email");
}
},
}),
admin({
ac,
roles,
}),
nextCookies(),
],
});
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "mysql",
}),
secret: process.env.BETTER_AUTH_SECRET || "fallback-secret-for-development",
baseURL: process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000",
emailAndPassword: {
enabled: true,
async sendResetPassword(data, request) {
// Send password reset email using our email service
try {
const resetUrl = `${process.env.NEXT_PUBLIC_APP_URL}/reset-password?token=${data.token}`;

const result = await emailService.sendPasswordResetEmail(
...
);

if (!result.success) {
console.error("Failed to send password reset email:", result.error);
throw new Error("Failed to send password reset email");
}

console.log(
"Password reset email sent successfully:",
result.messageId
);
} catch (error) {
console.error("Error sending password reset email:", error);
throw error;
}
},
},
plugins: [
customSession(async ({ user, session }) => {
type RoleType = keyof typeof roles;
return {
user: {
...user,
role: (user as any).role as RoleType,
},
session,
};
}),
magicLink({
sendMagicLink: async ({ email, url }) => {
const result = await emailService.sendMagicLinkEmail(
{ email },
{
magicLink: url,
appName: process.env.NEXT_PUBLIC_APP_NAME || "Your App",
appUrl: process.env.NEXT_PUBLIC_APP_URL || "https://yourapp.com",
}
);
if (!result.success) {
console.error("Failed to send magic link email:", result.error);
throw new Error("Failed to send magic link email");
}
},
}),
admin({
ac,
roles,
}),
nextCookies(),
],
});
I had to remove imports and the sendPaswordResetEmail to fit it here, but I don't think they would be a factor here
nikatune
nikatune4mo ago
can you update to better-auth v.13
SNiKerDoDle
SNiKerDoDleOP4mo ago
Just tried, doesn't seem to fix. Should I update next as well?
nikatune
nikatune4mo ago
maybe its because of customSession plugin can you remove it and try to build ?
SNiKerDoDle
SNiKerDoDleOP4mo ago
doesn't seem to fix it. I'm removing pieces of the config to try just random things now barebones seemingly isn't working either though leaving only password in it and the prisma adaptor thing
Solution
SNiKerDoDle
SNiKerDoDle4mo ago
This ended up being I just needed to delete my node_modules

Did you find this page helpful?