generated from KBVE/nodepy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappwrite.js
48 lines (40 loc) · 949 Bytes
/
appwrite.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const {
Client,
Users,
Databases,
Permission,
Role,
Query,
} = require("node-appwrite");
if (process.env.NODE_ENV !== "production") {
require("dotenv").config();
}
const appwrite = new Client()
.setEndpoint("https://ap.kbve.com/v1")
.setProject("6436a6dc9a6b48db802f")
.setKey(`${process.env.KBVE_API}`)
.setSelfSigned();
const db = new Databases(appwrite);
async function validApiKey(uuid, api) {
let valid = "kbve";
try {
const { documents, total } = await db.listDocuments("user", "user_apikey", [
Query.equal("user_id", uuid),
Query.equal("user_kbve_apikey", api),
]);
if (total === 0) {
//console.log(`${total} API Keys for ${uuid}`);
return valid;
} else {
valid = documents[0];
//console.log(valid);
return valid;
}
} catch (error) {
console.log(error);
return valid;
} finally {
return valid;
}
}
module.exports = validApiKey;