`auth.api.forgotPassword` not throwing error

For this configuration:

export const auth = betterAuth({
  database: new Pool({
    connectionString: process.env.DATABASE_URL
  }),
  emailAndPassword: {
    enabled: true,
    minPasswordLength: 6,
    requireEmailVerification: true,
    sendResetPassword: async ({ user, url, token }, request) => {
      await sendBetterPasswordResetEmail(user.email, url);
    }
  },
  emailVerification: {
    sendOnSignUp: true,
    autoSignInAfterVerification: true,
    sendVerificationEmail: async ({ user, url, token }, request) => {
      await sendBetterVerificationEmail(user.email, url);
    }
  },

  plugins: [nextCookies()]
});


If you pass an email address to auth.api.forgotPassword that does not exist in the databse, BetterAuth will return {status: true} and will not throw an error. There is therefore no way to catch this error and display something to the user without making more DB requests.

try {
  const { status } = await auth.api.forgetPassword({
    body: {
      email,
      redirectTo: "/auth/new-password"
    }
  });

} catch (error: unknown) {
  if (error instanceof APIError) return { error: error.message };
  return { error: "Something went wrong" };
}
Was this page helpful?