Skip to content

Commit 7fd4ff1

Browse files
authored
Merge pull request #286 from peakshift/feat/judges-scorecards
Feat: Tournament Judging Admin Pages
2 parents 51d7509 + 092b326 commit 7fd4ff1

File tree

129 files changed

+8306
-621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+8306
-621
lines changed

api/auth/utils/consts.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const adminUsersIds = [3, 9, 37, 1111, 1293, 2215];
2+
3+
const tournamentOrganizers = {
4+
1: [9],
5+
2: [9],
6+
4: [9],
7+
};
8+
9+
module.exports = {
10+
adminUsersIds,
11+
tournamentOrganizers,
12+
};

api/auth/utils/helperFuncs.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const jose = require("jose");
33
const { JWT_SECRET } = require("../../utils/consts");
44
const env = require("../../utils/consts");
55
const { generatePrivateKey, getPublicKey } = require("../../utils/nostr-tools");
6+
const { adminUsersIds, tournamentOrganizers } = require("./consts");
67

78
const getUserByPubKey = (pubKey) => {
89
if (!pubKey) return null;
@@ -93,10 +94,34 @@ const createNewUser = async (pubKey) => {
9394
});
9495
};
9596

97+
function verifyInternalAuthHeader(authHeader) {
98+
const authToken = authHeader?.split(" ")[1];
99+
if (authToken !== env.INTERNAL_FUNCTIONS_API_TOKEN) {
100+
return false;
101+
}
102+
return true;
103+
}
104+
105+
function isAdmin(userId) {
106+
if (!userId) return false;
107+
return adminUsersIds.includes(userId);
108+
}
109+
110+
function isTournamentOrganizer(userId, tournamentId) {
111+
if (!userId || !tournamentId) return false;
112+
113+
return true;
114+
115+
return tournamentOrganizers[tournamentId]?.includes(userId);
116+
}
117+
96118
module.exports = {
97119
getUserByPubKey,
98120
getUserById,
99121
generateAuthToken,
100122
getAuthCookieConfig,
101123
createNewUser,
124+
verifyInternalAuthHeader,
125+
isAdmin,
126+
isTournamentOrganizer,
102127
};

0 commit comments

Comments
 (0)