From 9dae1b4ea25ef0f371d846eada5109924b0e078d Mon Sep 17 00:00:00 2001 From: Saviru Date: Fri, 2 Jan 2026 11:51:06 +0530 Subject: [PATCH] feat: add `auth.api.verifyPassword` (#6934) Co-authored-by: Alex Yang --- docs/content/docs/concepts/users-accounts.mdx | 21 ++- packages/better-auth/src/api/index.ts | 2 + packages/better-auth/src/api/routes/index.ts | 2 +- ...eset-password.test.ts => password.test.ts} | 75 +++++++++ .../routes/{reset-password.ts => password.ts} | 59 +++++++ .../__snapshots__/open-api.test.ts.snap | 147 ++++++++++++++++++ 6 files changed, 303 insertions(+), 3 deletions(-) rename packages/better-auth/src/api/routes/{reset-password.test.ts => password.test.ts} (85%) rename packages/better-auth/src/api/routes/{reset-password.ts => password.ts} (88%) diff --git a/docs/content/docs/concepts/users-accounts.mdx b/docs/content/docs/concepts/users-accounts.mdx index bbc00145d7..e5ad593c61 100644 --- a/docs/content/docs/concepts/users-accounts.mdx +++ b/docs/content/docs/concepts/users-accounts.mdx @@ -140,6 +140,21 @@ await auth.api.setPassword({ headers: await headers() // headers containing the user's session token }); ``` +### Verify Password + +The `verifyPassword` function allows you to verify a user's current password. This is useful for confirming user identity before performing sensitive operations like updating security settings. This function can only be called from the server. + +```ts +await auth.api.verifyPassword({ + body: { + password: "user-password" // required + }, + headers: await headers() // headers containing the user's session token +}); +``` + +For OAuth users who don't have passwords, consider using email verification or fresh session checks for sensitive operations instead. + ## Delete User @@ -453,8 +468,10 @@ Users already signed in can manually link their account to additional social pro ```ts await auth.api.setPassword({ - headers: /* headers containing the user's session token */, - password: /* new password */ + body: { + newPassword: "new-password", // required + }, + headers: await headers() // headers containing the user's session token }); ``` diff --git a/packages/better-auth/src/api/index.ts b/packages/better-auth/src/api/index.ts index da32e41f9c..cebe6e77bb 100644 --- a/packages/better-auth/src/api/index.ts +++ b/packages/better-auth/src/api/index.ts @@ -42,6 +42,7 @@ import { unlinkAccount, updateUser, verifyEmail, + verifyPassword, } from "./routes"; import { toAuthEndpoints } from "./to-auth-endpoints"; @@ -216,6 +217,7 @@ export function getEndpoints