clapper / src /lib /hf /getCurrentOwner.ts
jbilcke-hf's picture
jbilcke-hf HF staff
add linter and prettifier
c1f12bf
raw
history blame
No virus
593 Bytes
import { Credentials, whoAmI } from '@huggingface/hub'
export async function getCurrentOwner(apiKey: string): Promise<string> {
const accessToken = apiKey || ''
if (!accessToken) {
throw new Error(`cannot list spaces without a Hugging Face access token`)
}
const credentials: Credentials = { accessToken }
let username = ''
try {
const { name } = await whoAmI({ credentials })
username = name
if (!username) {
throw new Error(`returned username is empty`)
}
} catch (err) {
throw new Error(`cannot list spaces: ${err}`)
}
return username
}