26 lines
1.2 KiB
JavaScript
26 lines
1.2 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.deleteByUserId = deleteByUserId;
|
|
exports.create = create;
|
|
exports.findValidByTokenHash = findValidByTokenHash;
|
|
exports.markUsed = markUsed;
|
|
exports.deleteStale = deleteStale;
|
|
const connection_1 = require("../db/connection");
|
|
async function deleteByUserId(userId) {
|
|
await (0, connection_1.query)('DELETE FROM password_reset_tokens WHERE user_id = $1', [userId]);
|
|
}
|
|
async function create(userId, tokenHash, expiresAt) {
|
|
await (0, connection_1.query)('INSERT INTO password_reset_tokens (user_id, token_hash, expires_at) VALUES ($1, $2, $3)', [userId, tokenHash, expiresAt]);
|
|
}
|
|
async function findValidByTokenHash(tokenHash) {
|
|
const rows = await (0, connection_1.query)(`SELECT id, user_id FROM password_reset_tokens
|
|
WHERE token_hash = $1 AND expires_at > NOW() AND used_at IS NULL`, [tokenHash]);
|
|
return rows[0] ?? null;
|
|
}
|
|
async function markUsed(id) {
|
|
await (0, connection_1.query)('UPDATE password_reset_tokens SET used_at = NOW() WHERE id = $1', [id]);
|
|
}
|
|
async function deleteStale() {
|
|
await (0, connection_1.query)('DELETE FROM password_reset_tokens WHERE expires_at <= NOW() OR used_at IS NOT NULL');
|
|
}
|
|
//# sourceMappingURL=passwordResetRepository.js.map
|