This commit is contained in:
2024-01-23 17:07:19 -05:00
parent 4aea6a8e4c
commit 173277cc8b
21 changed files with 5312 additions and 70 deletions

View File

@ -0,0 +1,23 @@
const { hash, compareHash } = require("./bcrypt.js");
const { apikeyModel } = require("../database/model/apiKeyModel");
const { generateUUID } = require("./generateUUID.js");
//can be used for api key or token. Both are the same logic
async function addAPIKey(userId, permission) {
let hashtoken = await generateUUID();
let apikey = await hash(hashtoken);
let token = await apikeyModel.create({
userId: userId,
apikey: apikey,
permission: permission,
});
//user token with - tokenid is table id
return token.id + "-" + hashtoken;
}
module.exports = {
addAPIKey
};