Yaltopia-FIFA/lib/auth/reset-email-cooldown.ts
Kirubel-Kibru-Yaltopia 89440985f1
Some checks failed
Deploy to Cloudflare Workers / deploy (push) Has been cancelled
x
2026-05-24 21:46:10 +03:00

24 lines
779 B
TypeScript

/** Client-only guard so users do not hammer Supabase auth email endpoints. */
const STORAGE_KEY = "yaltopia_forgot_password_cooldown_until";
/** Minimum wait between reset attempts from this browser */
export const RESET_EMAIL_COOLDOWN_MS = 120_000;
export function getResetEmailCooldownRemainingMs(): number {
if (typeof window === "undefined") return 0;
const until = Number(localStorage.getItem(STORAGE_KEY) || 0);
return Math.max(0, until - Date.now());
}
export function startResetEmailCooldown(): void {
if (typeof window === "undefined") return;
localStorage.setItem(
STORAGE_KEY,
String(Date.now() + RESET_EMAIL_COOLDOWN_MS)
);
}
export function formatCooldownSeconds(ms: number): number {
return Math.ceil(ms / 1000);
}