ai-manga-factory / src /lib /usePersistedOAuth.ts
jbilcke-hf's picture
jbilcke-hf HF staff
working on the Hugging Face Sign-In
0ed5b20
raw
history blame
830 Bytes
"use client"
import { useLocalStorage } from "usehooks-ts"
import { OAuthResult } from "@huggingface/hub"
import { defaultSettings } from "@/app/interface/settings-dialog/defaultSettings"
import { localStorageKeys } from "@/app/interface/settings-dialog/localStorageKeys"
import { getValidOAuth } from "./getValidOAuth"
export function usePersistedOAuth(): [OAuthResult | undefined, (oauthResult: OAuthResult) => void] {
const [serializedHuggingFaceOAuth, setSerializedHuggingFaceOAuth] = useLocalStorage<string>(
localStorageKeys.huggingFaceOAuth,
defaultSettings.huggingFaceOAuth
)
const oauthResult = getValidOAuth(serializedHuggingFaceOAuth)
const setOAuthResult = (oauthResult: OAuthResult) => {
setSerializedHuggingFaceOAuth(JSON.stringify(oauthResult))
}
return [oauthResult, setOAuthResult]
}