refactor: dont load all tokens in verify token

use sortedSetsRemove
isekai-main
Barış Soner Uşaklı 2 years ago
parent 11bfeaf130
commit 2fe193d68f

@ -94,9 +94,11 @@ utils.tokens.roll = async (token) => {
const updates = [
db.rename(`token:${token}`, `token:${newToken}`),
db.sortedSetRemove(`tokens:createtime`, token),
db.sortedSetRemove(`tokens:uid`, token),
db.sortedSetRemove(`tokens:lastSeen`, token),
db.sortedSetsRemove([
`tokens:createtime`,
`tokens:uid`,
`tokens:lastSeen`,
], token),
db.sortedSetAdd(`tokens:createtime`, createTime, newToken),
db.sortedSetAdd(`tokens:uid`, uid, newToken),
];
@ -113,9 +115,11 @@ utils.tokens.roll = async (token) => {
utils.tokens.delete = async (token) => {
await Promise.all([
db.delete(`token:${token}`),
db.sortedSetRemove(`tokens:createtime`, token),
db.sortedSetRemove(`tokens:uid`, token),
db.sortedSetRemove(`tokens:lastSeen`, token),
db.sortedSetsRemove([
`tokens:createtime`,
`tokens:uid`,
`tokens:lastSeen`,
], token),
]);
};

@ -45,8 +45,7 @@ Auth.getLoginStrategies = function () {
};
Auth.verifyToken = async function (token, done) {
const tokens = await api.utils.tokens.list();
const tokenObj = tokens.filter((t => t.token === token)).pop();
const tokenObj = await api.utils.tokens.get(token);
const uid = tokenObj ? tokenObj.uid : undefined;
if (uid !== undefined) {

Loading…
Cancel
Save