Spaces:
Runtime error
Runtime error
Andrew
commited on
Commit
·
087512c
1
Parent(s):
245b57f
refactor(auth): support multi-provider user lookup in API auth
Browse files- src/lib/server/auth.ts +11 -2
src/lib/server/auth.ts
CHANGED
|
@@ -301,7 +301,13 @@ export async function authenticateRequest(
|
|
| 301 |
|
| 302 |
const cacheHit = await collections.tokenCaches.findOne({ tokenHash: hash });
|
| 303 |
if (cacheHit) {
|
| 304 |
-
const user =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
if (!user) {
|
| 306 |
throw new Error("User not found");
|
| 307 |
}
|
|
@@ -322,7 +328,10 @@ export async function authenticateRequest(
|
|
| 322 |
}
|
| 323 |
|
| 324 |
const data = await response.json();
|
| 325 |
-
const user =
|
|
|
|
|
|
|
|
|
|
| 326 |
if (!user) {
|
| 327 |
throw new Error("User not found");
|
| 328 |
}
|
|
|
|
| 301 |
|
| 302 |
const cacheHit = await collections.tokenCaches.findOne({ tokenHash: hash });
|
| 303 |
if (cacheHit) {
|
| 304 |
+
const user =
|
| 305 |
+
(await collections.users.findOne({
|
| 306 |
+
$or: [
|
| 307 |
+
{ authProvider: "huggingface", authId: cacheHit.userId },
|
| 308 |
+
{ hfUserId: cacheHit.userId },
|
| 309 |
+
],
|
| 310 |
+
})) || null;
|
| 311 |
if (!user) {
|
| 312 |
throw new Error("User not found");
|
| 313 |
}
|
|
|
|
| 328 |
}
|
| 329 |
|
| 330 |
const data = await response.json();
|
| 331 |
+
const user =
|
| 332 |
+
(await collections.users.findOne({
|
| 333 |
+
$or: [{ authProvider: "huggingface", authId: data.id }, { hfUserId: data.id }],
|
| 334 |
+
})) || null;
|
| 335 |
if (!user) {
|
| 336 |
throw new Error("User not found");
|
| 337 |
}
|