Spaces:
Sleeping
Sleeping
File size: 830 Bytes
0ed5b20 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
"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]
} |