File size: 1,371 Bytes
b022cb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
import { useLocalStorage } from "usehooks-ts"

import { LLMVendor, RenderingModelVendor } from "@/types"
import { localStorageKeys } from "@/app/interface/settings-dialog/localStorageKeys"
import { defaultSettings } from "@/app/interface/settings-dialog/defaultSettings"

import { useDynamicConfig } from "./useDynamicConfig"

// we don't want to display the login wall to people forking the project,
// or to people who selected no hugging face server at all
export function useShouldDisplayLoginWall() {
  const { config, isConfigReady } = useDynamicConfig()

  const clientId = config.oauthClientId
  const enableOAuth = config.enableHuggingFaceOAuth
  const enableOAuthWall = config.enableHuggingFaceOAuthWall

  const isConfigEnablingOAuthWall = Boolean(
    clientId &&
    enableOAuth &&
    enableOAuthWall
  )

  const [renderingModelVendor,] = useLocalStorage<RenderingModelVendor>(
    localStorageKeys.renderingModelVendor,
    defaultSettings.renderingModelVendor
  )
  const [llmVendor,] = useLocalStorage<LLMVendor>(
    localStorageKeys.llmVendor,
    defaultSettings.llmVendor
  )

  const isUsingOneOfTheDefaultServices =
    renderingModelVendor === "SERVER" ||
    llmVendor === "SERVER"


  const shouldDisplayLoginWall =
    isConfigReady &&
    isConfigEnablingOAuthWall &&
    isUsingOneOfTheDefaultServices 
    
  return shouldDisplayLoginWall
}