Spaces:
Paused
Paused
Even more debug logs
Browse files
src/routes/login/callback/updateUser.ts
CHANGED
|
@@ -11,34 +11,40 @@ import { addWeeks } from "date-fns";
|
|
| 11 |
import { OIDConfig } from "$lib/server/auth";
|
| 12 |
import { HF_ORG_ADMIN, HF_ORG_EARLY_ACCESS } from "$env/static/private";
|
| 13 |
import { logger } from "$lib/server/logger";
|
| 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 |
export async function updateUser(params: {
|
| 44 |
userData: UserinfoResponse;
|
|
@@ -112,9 +118,11 @@ export async function updateUser(params: {
|
|
| 112 |
if (hfUserId) {
|
| 113 |
if (adminIds !== null) {
|
| 114 |
isAdmin = adminIds.includes(hfUserId);
|
|
|
|
| 115 |
}
|
| 116 |
if (earlyAccessIds !== null) {
|
| 117 |
isEarlyAccess = earlyAccessIds.includes(hfUserId);
|
|
|
|
| 118 |
}
|
| 119 |
}
|
| 120 |
|
|
|
|
| 11 |
import { OIDConfig } from "$lib/server/auth";
|
| 12 |
import { HF_ORG_ADMIN, HF_ORG_EARLY_ACCESS } from "$env/static/private";
|
| 13 |
import { logger } from "$lib/server/logger";
|
| 14 |
+
import { building } from "$app/environment";
|
| 15 |
+
|
| 16 |
+
let earlyAccessIds: string[] | null = null;
|
| 17 |
+
let adminIds: string[] | null = null;
|
| 18 |
+
|
| 19 |
+
if (!building) {
|
| 20 |
+
earlyAccessIds = HF_ORG_EARLY_ACCESS
|
| 21 |
+
? await fetch(`https://huggingface.co/api/organizations/${HF_ORG_EARLY_ACCESS}/members`)
|
| 22 |
+
.then((res) => res.json())
|
| 23 |
+
.then((res: Array<{ _id: string }>) => res.map((user: { _id: string }) => user._id))
|
| 24 |
+
.then((res) => {
|
| 25 |
+
logger.debug(`Found ${res.length} early access members`);
|
| 26 |
+
return res;
|
| 27 |
+
})
|
| 28 |
+
.catch((err) => {
|
| 29 |
+
logger.error(err, "Failed to fetch early access members");
|
| 30 |
+
return null;
|
| 31 |
+
})
|
| 32 |
+
: null;
|
| 33 |
+
|
| 34 |
+
adminIds = HF_ORG_ADMIN
|
| 35 |
+
? await fetch(`https://huggingface.co/api/organizations/${HF_ORG_ADMIN}/members`)
|
| 36 |
+
.then((res) => res.json())
|
| 37 |
+
.then((res: Array<{ _id: string }>) => res.map((user) => user._id))
|
| 38 |
+
.then((res) => {
|
| 39 |
+
logger.debug(`Found ${res.length} admin members`);
|
| 40 |
+
return res;
|
| 41 |
+
})
|
| 42 |
+
.catch((err) => {
|
| 43 |
+
logger.error(err, "Failed to fetch admin members");
|
| 44 |
+
return null;
|
| 45 |
+
})
|
| 46 |
+
: null;
|
| 47 |
+
}
|
| 48 |
|
| 49 |
export async function updateUser(params: {
|
| 50 |
userData: UserinfoResponse;
|
|
|
|
| 118 |
if (hfUserId) {
|
| 119 |
if (adminIds !== null) {
|
| 120 |
isAdmin = adminIds.includes(hfUserId);
|
| 121 |
+
logger.info(`Setting admin to ${isAdmin} for user ${hfUserId}`);
|
| 122 |
}
|
| 123 |
if (earlyAccessIds !== null) {
|
| 124 |
isEarlyAccess = earlyAccessIds.includes(hfUserId);
|
| 125 |
+
logger.info(`Setting early access to ${isEarlyAccess} for user ${hfUserId}`);
|
| 126 |
}
|
| 127 |
}
|
| 128 |
|