File size: 696 Bytes
58379d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 { localStorageHuggingFaceOAuthKey } from "@/app/config"

import { getValidOAuth } from "./getValidOAuth"

export function usePersistedOAuth(): [OAuthResult | undefined, (oauthResult: OAuthResult) => void] {
  const [serializedHuggingFaceOAuth, setSerializedHuggingFaceOAuth] = useLocalStorage<string>(
    localStorageHuggingFaceOAuthKey,
    ""
  )

  const oauthResult = getValidOAuth(serializedHuggingFaceOAuth)

  const setOAuthResult = (oauthResult: OAuthResult) => {
    setSerializedHuggingFaceOAuth(JSON.stringify(oauthResult))
  }

  return [oauthResult, setOAuthResult]
}