ChatGPT-Next-Web/app/components/auth.tsx

98 lines
2.9 KiB
TypeScript
Raw Normal View History

2023-06-06 18:18:24 +00:00
import styles from "./auth.module.scss";
import { IconButton } from "./button";
import { useNavigate } from "react-router-dom";
import { Path } from "../constant";
import { useAccessStore } from "../store";
import Locale from "../locales";
import BotIcon from "../icons/bot.svg";
import { useEffect } from "react";
import { getClientConfig } from "../config/client";
2023-06-06 18:18:24 +00:00
export function AuthPage() {
const navigate = useNavigate();
2023-11-07 16:34:31 +00:00
const accessStore = useAccessStore();
2023-06-06 18:18:24 +00:00
const goHome = () => navigate(Path.Home);
const goChat = () => navigate(Path.Chat);
2023-11-07 16:34:31 +00:00
const resetAccessCode = () => {
accessStore.update((access) => {
2023-11-09 18:43:30 +00:00
access.openaiApiKey = "";
2023-11-07 16:34:31 +00:00
access.accessCode = "";
});
}; // Reset access code to empty string
2023-06-06 18:18:24 +00:00
useEffect(() => {
if (getClientConfig()?.isApp) {
navigate(Path.Settings);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
2023-06-06 18:18:24 +00:00
return (
<div className={styles["auth-page"]}>
<div className={`no-dark ${styles["auth-logo"]}`}>
<BotIcon />
</div>
<div className={styles["auth-title"]}>{Locale.Auth.Title}</div>
<div className={styles["auth-tips"]}>{Locale.Auth.Tips}</div>
<input
className={styles["auth-input"]}
2023-06-09 04:39:42 +00:00
type="password"
2023-06-06 18:18:24 +00:00
placeholder={Locale.Auth.Input}
2023-11-07 16:34:31 +00:00
value={accessStore.accessCode}
2023-06-06 18:18:24 +00:00
onChange={(e) => {
2023-11-07 16:34:31 +00:00
accessStore.update(
(access) => (access.accessCode = e.currentTarget.value),
);
2023-06-06 18:18:24 +00:00
}}
/>
2024-05-16 07:03:14 +00:00
{/*{!accessStore.hideUserApiKey ? (*/}
{/* <>*/}
{/* <div className={styles["auth-tips"]}>{Locale.Auth.SubTips}</div>*/}
{/* <input*/}
{/* className={styles["auth-input"]}*/}
{/* type="password"*/}
{/* placeholder={Locale.Settings.Access.OpenAI.ApiKey.Placeholder}*/}
{/* value={accessStore.openaiApiKey}*/}
{/* onChange={(e) => {*/}
{/* accessStore.update(*/}
{/* (access) => (access.openaiApiKey = e.currentTarget.value),*/}
{/* );*/}
{/* }}*/}
{/* />*/}
{/* <input*/}
{/* className={styles["auth-input"]}*/}
{/* type="password"*/}
{/* placeholder={Locale.Settings.Access.Google.ApiKey.Placeholder}*/}
{/* value={accessStore.googleApiKey}*/}
{/* onChange={(e) => {*/}
{/* accessStore.update(*/}
{/* (access) => (access.googleApiKey = e.currentTarget.value),*/}
{/* );*/}
{/* }}*/}
{/* />*/}
{/* </>*/}
{/*) : null}*/}
2023-06-06 18:18:24 +00:00
<div className={styles["auth-actions"]}>
<IconButton
text={Locale.Auth.Confirm}
type="primary"
onClick={goChat}
2023-06-06 18:18:24 +00:00
/>
<IconButton
text={Locale.Auth.Later}
onClick={() => {
resetAccessCode();
goHome();
}}
/>
2023-06-06 18:18:24 +00:00
</div>
</div>
);
}