Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 733 Bytes
b3c7e0f |
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 26 27 28 29 30 31 32 |
import { useEffect, useState } from "react"
import { oauthHandleRedirectIfPresent, oauthLoginUrl } from "@huggingface/hub"
export function useHuggingFaceLogin(onLogin?: (data: any) => void) {
const [isLoggedIn, setLoggedIn] = useState(false)
const [oauthResult, setOauthResult] = useState<any>({})
useEffect(() => {
const fn = async () => {
const res = await oauthHandleRedirectIfPresent()
if (res) {
setOauthResult(res)
setLoggedIn(true)
onLogin?.(res)
}
}
fn()
}, [])
const login = async () => {
window.location.href = await oauthLoginUrl()
}
console.log(JSON.stringify(oauthResult, null, 2))
return {
isLoggedIn,
login,
oauthResult,
}
} |