UNPKG

@lobehub/chat

Version:

Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.

32 lines (24 loc) 729 B
import { getAppConfig } from '@/envs/app'; import { ChatErrorType } from '@/types/fetch'; interface AuthConfig { accessCode?: string | null; apiKey?: string | null; oauthAuthorized?: boolean; } export const checkAuth = ({ apiKey, accessCode, oauthAuthorized }: AuthConfig) => { // If authorized by oauth if (oauthAuthorized) { return { auth: true }; } const { ACCESS_CODES } = getAppConfig(); // if apiKey exist if (apiKey) { return { auth: true }; } // if accessCode doesn't exist if (!ACCESS_CODES.length) return { auth: true }; if (!accessCode || !ACCESS_CODES.includes(accessCode)) { return { auth: false, error: ChatErrorType.InvalidAccessCode }; } return { auth: true }; };