fix(one-time-token): typo and clean (#4579)

This commit is contained in:
Gabriel
2025-09-11 17:04:00 -03:00
committed by GitHub
parent 1bb1232632
commit 01365ee033

View File

@@ -8,7 +8,7 @@ import { sessionMiddleware } from "../../api";
import { generateRandomString } from "../../crypto";
import type { GenericEndpointContext, Session, User } from "../../types";
interface OneTimeTokenopts {
interface OneTimeTokenOptions {
/**
* Expires in minutes
*
@@ -41,11 +41,11 @@ interface OneTimeTokenopts {
| { type: "custom-hasher"; hash: (token: string) => Promise<string> };
}
export const oneTimeToken = (options?: OneTimeTokenopts) => {
export const oneTimeToken = (options?: OneTimeTokenOptions) => {
const opts = {
storeToken: "plain",
...options,
} satisfies OneTimeTokenopts;
} satisfies OneTimeTokenOptions;
async function storeToken(ctx: GenericEndpointContext, token: string) {
if (opts.storeToken === "hashed") {
@@ -146,17 +146,14 @@ export const oneTimeToken = (options?: OneTimeTokenopts) => {
message: "Invalid token",
});
}
await c.context.internalAdapter.deleteVerificationValue(
verificationValue.id,
);
if (verificationValue.expiresAt < new Date()) {
await c.context.internalAdapter.deleteVerificationValue(
verificationValue.id,
);
throw c.error("BAD_REQUEST", {
message: "Token expired",
});
}
await c.context.internalAdapter.deleteVerificationValue(
verificationValue.id,
);
const session = await c.context.internalAdapter.findSession(
verificationValue.value,
);