mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-03 04:19:06 +08:00
Add last used on logic (#2643)
* Add last used on logic * Remove lodash
This commit is contained in:
parent
6645c2d4bd
commit
7d19f54828
4 changed files with 15 additions and 0 deletions
|
@ -46,6 +46,7 @@ class ApeKeysController {
|
|||
hash: saltyHash,
|
||||
createdOn: Date.now(),
|
||||
modifiedOn: Date.now(),
|
||||
lastUsedOn: -1,
|
||||
};
|
||||
|
||||
const apeKeyId = await ApeKeysDAO.addApeKey(uid, apeKey);
|
||||
|
|
|
@ -72,6 +72,16 @@ class ApeKeysDAO {
|
|||
const apeKeys = _.omit(user.apeKeys, keyId);
|
||||
await UsersDAO.setApeKeys(uid, apeKeys);
|
||||
}
|
||||
|
||||
static async updateLastUsedOn(
|
||||
user: MonkeyTypes.User,
|
||||
keyId: string
|
||||
): Promise<void> {
|
||||
checkIfKeyExists(user.apeKeys, keyId);
|
||||
|
||||
user.apeKeys[keyId].lastUsedOn = Date.now();
|
||||
await UsersDAO.setApeKeys(user.uid, user.apeKeys);
|
||||
}
|
||||
}
|
||||
|
||||
export default ApeKeysDAO;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import _ from "lodash";
|
||||
import { compare } from "bcrypt";
|
||||
import UsersDAO from "../dao/user";
|
||||
import ApeKeysDAO from "../dao/ape-keys";
|
||||
import MonkeyError from "../utils/error";
|
||||
import { verifyIdToken } from "../utils/auth";
|
||||
import { base64UrlDecode } from "../utils/misc";
|
||||
|
@ -165,6 +166,8 @@ async function authenticateWithApeKey(
|
|||
throw new MonkeyError(400, "Invalid ApeKey");
|
||||
}
|
||||
|
||||
await ApeKeysDAO.updateLastUsedOn(keyOwner, keyId);
|
||||
|
||||
return {
|
||||
uid,
|
||||
email: keyOwner.email,
|
||||
|
|
1
backend/types/types.d.ts
vendored
1
backend/types/types.d.ts
vendored
|
@ -70,6 +70,7 @@ declare namespace MonkeyTypes {
|
|||
hash: string;
|
||||
createdOn: number;
|
||||
modifiedOn: number;
|
||||
lastUsedOn: number;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue