Spaces:
Paused
Paused
fix(featureflags): use correct env vars (#1405)
Browse files- chart/env/prod.yaml +2 -2
- src/routes/login/callback/updateUser.ts +28 -65
chart/env/prod.yaml
CHANGED
|
@@ -473,8 +473,8 @@ envVars:
|
|
| 473 |
"outputComponentIdx": 0
|
| 474 |
}
|
| 475 |
]
|
| 476 |
-
HF_ORG_ADMIN: '
|
| 477 |
-
HF_ORG_EARLY_ACCESS: '
|
| 478 |
|
| 479 |
infisical:
|
| 480 |
enabled: true
|
|
|
|
| 473 |
"outputComponentIdx": 0
|
| 474 |
}
|
| 475 |
]
|
| 476 |
+
HF_ORG_ADMIN: '644171cfbd0c97265298aa99'
|
| 477 |
+
HF_ORG_EARLY_ACCESS: '5e67bd5b1009063689407478'
|
| 478 |
|
| 479 |
infisical:
|
| 480 |
enabled: true
|
src/routes/login/callback/updateUser.ts
CHANGED
|
@@ -9,42 +9,8 @@ import crypto from "crypto";
|
|
| 9 |
import { sha256 } from "$lib/utils/sha256";
|
| 10 |
import { addWeeks } from "date-fns";
|
| 11 |
import { OIDConfig } from "$lib/server/auth";
|
| 12 |
-
import {
|
| 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;
|
|
@@ -67,6 +33,7 @@ export async function updateUser(params: {
|
|
| 67 |
email,
|
| 68 |
picture: avatarUrl,
|
| 69 |
sub: hfUserId,
|
|
|
|
| 70 |
} = z
|
| 71 |
.object({
|
| 72 |
preferred_username: z.string().optional(),
|
|
@@ -112,19 +79,19 @@ export async function updateUser(params: {
|
|
| 112 |
// Dynamically access user data based on NAME_CLAIM from environment
|
| 113 |
// This approach allows us to adapt to different OIDC providers flexibly.
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
|
| 129 |
logger.debug(
|
| 130 |
{
|
|
@@ -154,8 +121,7 @@ export async function updateUser(params: {
|
|
| 154 |
// update existing user if any
|
| 155 |
await collections.users.updateOne(
|
| 156 |
{ _id: existingUser._id },
|
| 157 |
-
{ $set: { username, name, avatarUrl, isAdmin, isEarlyAccess } }
|
| 158 |
-
{ ignoreUndefined: true }
|
| 159 |
);
|
| 160 |
|
| 161 |
// remove previous session if it exists and add new one
|
|
@@ -172,21 +138,18 @@ export async function updateUser(params: {
|
|
| 172 |
});
|
| 173 |
} else {
|
| 174 |
// user doesn't exist yet, create a new one
|
| 175 |
-
const { insertedId } = await collections.users.insertOne(
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
},
|
| 188 |
-
{ ignoreUndefined: true }
|
| 189 |
-
);
|
| 190 |
|
| 191 |
userId = insertedId;
|
| 192 |
|
|
|
|
| 9 |
import { sha256 } from "$lib/utils/sha256";
|
| 10 |
import { addWeeks } from "date-fns";
|
| 11 |
import { OIDConfig } from "$lib/server/auth";
|
| 12 |
+
import { env } from "$env/dynamic/private";
|
| 13 |
import { logger } from "$lib/server/logger";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
export async function updateUser(params: {
|
| 16 |
userData: UserinfoResponse;
|
|
|
|
| 33 |
email,
|
| 34 |
picture: avatarUrl,
|
| 35 |
sub: hfUserId,
|
| 36 |
+
orgs,
|
| 37 |
} = z
|
| 38 |
.object({
|
| 39 |
preferred_username: z.string().optional(),
|
|
|
|
| 79 |
// Dynamically access user data based on NAME_CLAIM from environment
|
| 80 |
// This approach allows us to adapt to different OIDC providers flexibly.
|
| 81 |
|
| 82 |
+
logger.info(
|
| 83 |
+
{
|
| 84 |
+
login_username: username,
|
| 85 |
+
login_name: name,
|
| 86 |
+
login_email: email,
|
| 87 |
+
login_orgs: orgs?.map((el) => el.sub),
|
| 88 |
+
},
|
| 89 |
+
"user login"
|
| 90 |
+
);
|
| 91 |
+
// if using huggingface as auth provider, check orgs for earl access and amin rights
|
| 92 |
+
const isAdmin = (env.HF_ORG_ADMIN && orgs?.some((org) => org.sub === env.HF_ORG_ADMIN)) || false;
|
| 93 |
+
const isEarlyAccess =
|
| 94 |
+
(env.HF_ORG_EARLY_ACCESS && orgs?.some((org) => org.sub === env.HF_ORG_EARLY_ACCESS)) || false;
|
| 95 |
|
| 96 |
logger.debug(
|
| 97 |
{
|
|
|
|
| 121 |
// update existing user if any
|
| 122 |
await collections.users.updateOne(
|
| 123 |
{ _id: existingUser._id },
|
| 124 |
+
{ $set: { username, name, avatarUrl, isAdmin, isEarlyAccess } }
|
|
|
|
| 125 |
);
|
| 126 |
|
| 127 |
// remove previous session if it exists and add new one
|
|
|
|
| 138 |
});
|
| 139 |
} else {
|
| 140 |
// user doesn't exist yet, create a new one
|
| 141 |
+
const { insertedId } = await collections.users.insertOne({
|
| 142 |
+
_id: new ObjectId(),
|
| 143 |
+
createdAt: new Date(),
|
| 144 |
+
updatedAt: new Date(),
|
| 145 |
+
username,
|
| 146 |
+
name,
|
| 147 |
+
email,
|
| 148 |
+
avatarUrl,
|
| 149 |
+
hfUserId,
|
| 150 |
+
isAdmin,
|
| 151 |
+
isEarlyAccess,
|
| 152 |
+
});
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
userId = insertedId;
|
| 155 |
|