UNPKG

better-auth

Version:

The most comprehensive authentication framework for TypeScript.

26 lines (25 loc) 1.03 kB
import { base64Url } from "@better-auth/utils/base64"; import { createHash } from "@better-auth/utils/hash"; //#region src/db/verification-token-storage.ts const defaultKeyHasher = async (identifier) => { const hash = await createHash("SHA-256").digest(new TextEncoder().encode(identifier)); return base64Url.encode(new Uint8Array(hash), { padding: false }); }; async function processIdentifier(identifier, option) { if (!option || option === "plain") return identifier; if (option === "hashed") return defaultKeyHasher(identifier); if (typeof option === "object" && "hash" in option) return option.hash(identifier); return identifier; } function getStorageOption(identifier, config) { if (!config) return; if (typeof config === "object" && "default" in config) { if (config.overrides) { for (const [prefix, option] of Object.entries(config.overrides)) if (identifier.startsWith(prefix)) return option; } return config.default; } return config; } //#endregion export { getStorageOption, processIdentifier };