import styles from "./auth.module.scss"; import { IconButton } from "./button"; import { useNavigate } from "react-router-dom"; import { Path } from "../constant"; import { useAccessStore, useAppConfig, useChatStore } from "../store"; import Locale from "../locales"; import BotIcon from "../icons/bot.svg"; import { useEffect } from "react"; import { getClientConfig } from "../config/client"; export function AuthPage() { const navigate = useNavigate(); const access = useAccessStore(); const config = useAppConfig(); const goHome = () => navigate(Path.Home); const goChat = () => navigate(Path.Chat); const resetAccessCode = () => { access.update((config) => (config.accessCode = "")); config.update((config) => (config.providerConfig.openai.apiKey = "")); }; // Reset access code to empty string useEffect(() => { if (getClientConfig()?.isApp) { navigate(Path.Settings); } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return (
{Locale.Auth.Title}
{Locale.Auth.Tips}
{ access.update( (config) => (config.accessCode = e.currentTarget.value), ); }} /> {!access.hideUserApiKey ? ( <>
{Locale.Auth.SubTips}
{ config.update( (config) => (config.providerConfig.openai.apiKey = e.currentTarget.value), ); }} /> ) : null}
{ resetAccessCode(); goHome(); }} />
); }