Spaces:
Sleeping
Sleeping
File size: 581 Bytes
b4b34c7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import { collections } from "./database";
import { decryptToken } from "./tokenEncryption";
import type { ObjectId } from "mongodb";
/**
* Retrieves and decrypts a user's Hugging Face token if available
*/
export async function getUserHFToken(userId: ObjectId): Promise<string | null> {
const userToken = await collections.userTokens.findOne({
userId,
provider: "huggingface",
});
if (!userToken) {
return null;
}
try {
return decryptToken(userToken.encryptedToken);
} catch (error) {
console.error("Failed to decrypt user token:", error);
return null;
}
}
|