@cocalc/database
Version:
CoCalc: code for working with our PostgreSQL database
32 lines • 1.27 kB
JavaScript
;
/*
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.get_remember_me = void 0;
const { one_result } = require("../postgres-base");
const awaiting_1 = require("awaiting");
const hof_1 = require("async-await-utils/hof");
async function _get_remember_me(db, hash, cache) {
// returns undefined for now account or the account_id of user we just authenticated
function f(cb) {
db._query({
cache,
query: "SELECT account_id, expire FROM remember_me",
where: {
// db-schema/auth defines the hash field as a "bpchar", hence do not cast to TEXT – otherwise this is a 100x slowdown
"hash = $::CHAR(127)": hash.slice(0, 127),
},
retry_until_success: { max_time: 60000, start_delay: 10000 },
cb: one_result("account_id", cb),
});
}
return await (0, awaiting_1.callback)(f);
}
exports.get_remember_me = (0, hof_1.reuseInFlight)(_get_remember_me, {
createKey: function (args) {
return args[1] + args[2];
},
});
//# sourceMappingURL=remember-me.js.map