Skip to content

Commit

Permalink
Even more debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarrazin committed Aug 12, 2024
1 parent 8e68159 commit 7eac22f
Showing 1 changed file with 36 additions and 28 deletions.
64 changes: 36 additions & 28 deletions src/routes/login/callback/updateUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,40 @@ import { addWeeks } from "date-fns";
import { OIDConfig } from "$lib/server/auth";
import { HF_ORG_ADMIN, HF_ORG_EARLY_ACCESS } from "$env/static/private";
import { logger } from "$lib/server/logger";

const earlyAccessIds = HF_ORG_EARLY_ACCESS
? await fetch(`https://huggingface.co/api/organizations/${HF_ORG_EARLY_ACCESS}/members`)
.then((res) => res.json())
.then((res: Array<{ _id: string }>) => res.map((user: { _id: string }) => user._id))
.then((res) => {
logger.debug(`Found ${res.length} early access members`);
return res;
})
.catch((err) => {
logger.error(err, "Failed to fetch early access members");
return null;
})
: null;

const adminIds = HF_ORG_ADMIN
? await fetch(`https://huggingface.co/api/organizations/${HF_ORG_ADMIN}/members`)
.then((res) => res.json())
.then((res: Array<{ _id: string }>) => res.map((user) => user._id))
.then((res) => {
logger.debug(`Found ${res.length} admin members`);
return res;
})
.catch((err) => {
logger.error(err, "Failed to fetch admin members");
return null;
})
: null;
import { building } from "$app/environment";

let earlyAccessIds: string[] | null = null;
let adminIds: string[] | null = null;

if (!building) {
earlyAccessIds = HF_ORG_EARLY_ACCESS
? await fetch(`https://huggingface.co/api/organizations/${HF_ORG_EARLY_ACCESS}/members`)
.then((res) => res.json())
.then((res: Array<{ _id: string }>) => res.map((user: { _id: string }) => user._id))
.then((res) => {
logger.debug(`Found ${res.length} early access members`);
return res;
})
.catch((err) => {
logger.error(err, "Failed to fetch early access members");
return null;
})
: null;

adminIds = HF_ORG_ADMIN
? await fetch(`https://huggingface.co/api/organizations/${HF_ORG_ADMIN}/members`)
.then((res) => res.json())
.then((res: Array<{ _id: string }>) => res.map((user) => user._id))
.then((res) => {
logger.debug(`Found ${res.length} admin members`);
return res;
})
.catch((err) => {
logger.error(err, "Failed to fetch admin members");
return null;
})
: null;
}

export async function updateUser(params: {
userData: UserinfoResponse;
Expand Down Expand Up @@ -112,9 +118,11 @@ export async function updateUser(params: {
if (hfUserId) {
if (adminIds !== null) {
isAdmin = adminIds.includes(hfUserId);
logger.info(`Setting admin to ${isAdmin} for user ${hfUserId}`);
}
if (earlyAccessIds !== null) {
isEarlyAccess = earlyAccessIds.includes(hfUserId);
logger.info(`Setting early access to ${isEarlyAccess} for user ${hfUserId}`);
}
}

Expand Down

0 comments on commit 7eac22f

Please sign in to comment.