mirror of
https://github.com/better-auth/better-auth.git
synced 2026-06-01 11:56:43 -05:00
fix(one-time-token): typo and clean (#4579)
This commit is contained in:
@@ -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,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user