Forgotten-password recovery
A user has forgotten an email/password account credential and needs a secure replacement flow.
Better Auth · Module
resetPassword completes Better Auth’s email/password recovery flow. After the user receives a token-bearing reset link, call it with the token and the replacement password.
Email/password reset requires a configured sendResetPassword callback to deliver a token-bearing URL. The client first requests the reset link; after the user reaches the reset page, resetPassword receives the new password and token, while token validity is controlled by resetPasswordTokenExpiresIn.
await authClient.resetPassword({ newPassword, token });| Name | Type | Description |
|---|---|---|
newPassword | string | The new password to assign to the user. |
token | string | The verification token from the reset link. |
The client methods return an object containing data and error, as shown in the documentation examples.
import { betterAuth } from "better-auth";
import { authClient } from "./auth-client";
export const auth = betterAuth({
emailAndPassword: {
enabled: true,
sendResetPassword: async ({ user, url }) => {
console.log(`Send reset link to ${user.email}: ${url}`);
},
},
});
const { data, error } = await authClient.requestPasswordReset({
email: "user@example.com",
redirectTo: "https://app.example.com/reset-password",
});
if (error) throw error;
const token = new URL(data?.url ?? "").searchParams.get("token");
if (!token) throw new Error("Missing reset token");
const result = await authClient.resetPassword({
newPassword: "new-secure-password",
token,
});
if (result.error) throw result.error;Configure the reset-email callback, request a reset link, then pass the link token and new password to the reset method.
A user has forgotten an email/password account credential and needs a secure replacement flow.
An application provides a reset page reached through the emailed token URL.
A security-sensitive application must invalidate current sessions after a successful password change.
Configure emailAndPassword.sendResetPassword to deliver the URL containing the reset token. Then call requestPasswordReset and, from the reset page, call resetPassword with newPassword and token.
Follow-up: How can existing sessions be invalidated after the change? Enable revokeSessionsOnPasswordReset; the documentation says this revokes all user sessions during reset.
The callback receives user, url, and token. The URL is intended for the user, while the token is the verification value needed to complete the reset.
Follow-up: What controls token lifetime? resetPasswordTokenExpiresIn sets the validity duration in seconds, with a documented default of 3600.
The password reset endpoint is separate from the request step: requestPasswordReset sends the link, and resetPassword changes the password using the token and new password.
Follow-up: What callback can observe completion? onPasswordReset runs after the new password is saved and, when configured, after sessions are revoked.
requestPasswordResetsendResetPasswordresetPasswordTokenExpiresInrevokeSessionsOnPasswordResetonPasswordReset