Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Commit 27a20c8

Browse files
committed
update(reverify): docs and code to be up-to-date
1 parent a073752 commit 27a20c8

File tree

4 files changed

+33
-37
lines changed

4 files changed

+33
-37
lines changed

apps/docs/content/docs/plugins/reverify.mdx

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
---
22
title: Reverify
3-
description: Prompt the user to re-verify their identity by providing a form of authentication for revalidation.
3+
description: Prompt the user to re-verify their identity by providing their password for revalidation.
44
---
55

66
<StatsBadge npmPackage="@better-auth-kit/reverify" />
77
<GithubButton url="https://github.com/ping-maxwell/better-auth-kit/tree/main/packages/plugins/reverify" />
88
<NpmButton url="https://www.npmjs.com/package/@better-auth-kit/reverify" />
99

10-
<Callout type="warn">
11-
#### This plugin is in Beta
12-
This plugin only supports password verification which returns a `valid` boolean, and does not support extending the current session yet.
13-
This will be added in a future release.
14-
</Callout>
15-
16-
If a user's session is not fresh, critical actions (e.g. deleting their account) will not be allowed.
17-
You would have to terminate their session, force them to sign-in again, and then be able to perform the action.
18-
Depending on your application, this may not be the best user experience. In some cases, routes can be protected and only accessible to active sessions. By terminating a session and making them sign-in, they're redirected to the login page and may not even know what happened.
10+
The purpose of this plugin is to allow the user to re-verify their identity without modifying their current session.
11+
An example use case is before deleting an API key, you would want to re-verify the user's
12+
identity to ensure they are the one deleting the key.
1913

20-
Using Reverify, you can prompt the user to re-verify their identity without logging them out or terminating their current session.
14+
<Callout>
15+
This plugin is not for the purpose of refreshing a session, if you want to refresh a session you can use any of the sign-in related methods.
16+
</Callout>
2117

2218
<Steps>
2319
<Step>
@@ -76,13 +72,4 @@ Using Reverify, you can prompt the user to re-verify their identity without logg
7672
</Step>
7773
</Steps>
7874

79-
<div className="h-10" />
80-
81-
<Callout>
82-
There are future plans to add more forms of authentication to reverify, such as:
83-
84-
- Phone number verification
85-
- Magic link & Email OTP verification
86-
- 2FA verification
87-
- Passkey verification
88-
</Callout>
75+
<div className="h-10" />

bun.lock

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/plugins/reverify/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@better-auth-kit/reverify",
3-
"version": "0.2.0",
3+
"version": "1.0.1",
44
"description": "Prompt the user to re-verify their identity by providing a form of authentication for revalidation.",
55
"type": "module",
66
"repository": {
@@ -29,11 +29,12 @@
2929
"license": "MIT",
3030
"devDependencies": {
3131
"@better-auth-kit/internal-build": "workspace:*",
32+
"@better-auth-kit/internal-utils": "workspace:*",
3233
"vitest": "^3.0.8",
3334
"@better-auth-kit/tests": "workspace:*"
3435
},
3536
"peerDependencies": {
36-
"better-auth": "^1.1.21"
37+
"better-auth": "^1.2.8"
3738
},
3839
"publishConfig": {
3940
"access": "public"

packages/plugins/reverify/src/index.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
sessionMiddleware,
66
} from "better-auth/api";
77
import { z } from "zod";
8+
import { tryCatch } from "@better-auth-kit/internal-utils";
89

910
export const reverify = () => {
1011
return {
@@ -21,22 +22,26 @@ export const reverify = () => {
2122
},
2223
async (ctx) => {
2324
const session = ctx.context.session;
24-
let validPassword = false;
25-
try {
26-
validPassword = await ctx.context.password.checkPassword(
27-
session.user.id,
28-
ctx,
25+
26+
const { data: validPassword, error } = await tryCatch(
27+
ctx.context.password.checkPassword(session.user.id, ctx),
28+
);
29+
30+
if (error) {
31+
logger.error(
32+
`[Better-Auth-Kit: Reverify] Error checking password`,
33+
error,
2934
);
30-
} catch (error: unknown) {
31-
logger.error(`[Reverify] Error checking password`, error);
3235
if (
3336
error instanceof APIError &&
3437
error?.body?.code === "INVALID_PASSWORD"
3538
) {
36-
logger.info(`[Reverify] Password is invalid`);
37-
return ctx.json({ valid: false });
39+
logger.info(`[Better-Auth-Kit: Reverify] Password is invalid`);
40+
return ctx.json({ valid: false, newSession: null });
3841
}
39-
throw error;
42+
throw new APIError("INTERNAL_SERVER_ERROR", {
43+
message: "Something went wrong while checking the password",
44+
});
4045
}
4146

4247
return ctx.json({ valid: validPassword });

0 commit comments

Comments
 (0)