round1
This commit is contained in:
23
consumerWebsite/functions/api.js
Normal file
23
consumerWebsite/functions/api.js
Normal 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
|
||||
};
|
Reference in New Issue
Block a user