forked from GithubProxy/ChatGPT-Next-Web
- 在 auth.tsx 中引入 Path 常量,以便统一管理路由路径 - 在 server.ts 中移除了未使用的 DEFAULT_GA_ID 常量,减少冗余代码
114 lines
3.5 KiB
TypeScript
114 lines
3.5 KiB
TypeScript
import styles from "./auth.module.scss";
|
|
import { IconButton } from "./button";
|
|
import { useState, useEffect } from "react";
|
|
import { useNavigate } from "react-router-dom";
|
|
import { useAccessStore } from "../store";
|
|
import { Path } from "../constant";
|
|
import Locale from "../locales";
|
|
import Delete from "../icons/close.svg";
|
|
import Arrow from "../icons/arrow.svg";
|
|
import Logo from "../icons/logo.svg";
|
|
import { useMobileScreen } from "@/app/utils";
|
|
import BotIcon from "../icons/bot.svg";
|
|
import { getClientConfig } from "../config/client";
|
|
import { PasswordInput } from "./ui-lib";
|
|
import LeftIcon from "@/app/icons/left.svg";
|
|
import { safeLocalStorage } from "@/app/utils";
|
|
import {
|
|
trackSettingsPageGuideToCPaymentClick,
|
|
trackAuthorizationPageButtonToCPaymentClick,
|
|
} from "../utils/auth-settings-events";
|
|
import clsx from "clsx";
|
|
|
|
const storage = safeLocalStorage();
|
|
|
|
export function AuthPage() {
|
|
const navigate = useNavigate();
|
|
const accessStore = useAccessStore();
|
|
const goHome = () => navigate(Path.Home);
|
|
const goChat = () => navigate(Path.Chat);
|
|
|
|
const resetAccessCode = () => {
|
|
accessStore.update((access) => {
|
|
access.openaiApiKey = "";
|
|
access.accessCode = "";
|
|
});
|
|
}; // Reset access code to empty string
|
|
|
|
useEffect(() => {
|
|
if (getClientConfig()?.isApp) {
|
|
navigate(Path.Settings);
|
|
}
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
|
|
return (
|
|
<div className={styles["auth-page"]}>
|
|
<div className={styles["auth-header"]}>
|
|
<IconButton
|
|
icon={<LeftIcon />}
|
|
text={Locale.Auth.Return}
|
|
onClick={() => navigate(Path.Home)}
|
|
></IconButton>
|
|
</div>
|
|
<div className={clsx("no-dark", styles["auth-logo"])}>
|
|
<BotIcon />
|
|
</div>
|
|
|
|
<PasswordInput
|
|
style={{ marginTop: "3vh", marginBottom: "3vh" }}
|
|
aria={Locale.Settings.ShowPassword}
|
|
aria-label={Locale.Auth.Input}
|
|
value={accessStore.accessCode}
|
|
type="text"
|
|
placeholder={Locale.Auth.Input}
|
|
onChange={(e) => {
|
|
accessStore.update(
|
|
(access) => (access.accessCode = e.currentTarget.value),
|
|
);
|
|
}}
|
|
/>
|
|
|
|
{!accessStore.hideUserApiKey ? (
|
|
<>
|
|
<div className={styles["auth-tips"]}>{Locale.Auth.SubTips}</div>
|
|
<PasswordInput
|
|
style={{ marginTop: "3vh", marginBottom: "3vh" }}
|
|
aria={Locale.Settings.ShowPassword}
|
|
aria-label={Locale.Settings.Access.OpenAI.ApiKey.Placeholder}
|
|
value={accessStore.openaiApiKey}
|
|
type="text"
|
|
placeholder={Locale.Settings.Access.OpenAI.ApiKey.Placeholder}
|
|
onChange={(e) => {
|
|
accessStore.update(
|
|
(access) => (access.openaiApiKey = e.currentTarget.value),
|
|
);
|
|
}}
|
|
/>
|
|
<PasswordInput
|
|
style={{ marginTop: "3vh", marginBottom: "3vh" }}
|
|
aria={Locale.Settings.ShowPassword}
|
|
aria-label={Locale.Settings.Access.Google.ApiKey.Placeholder}
|
|
value={accessStore.googleApiKey}
|
|
type="text"
|
|
placeholder={Locale.Settings.Access.Google.ApiKey.Placeholder}
|
|
onChange={(e) => {
|
|
accessStore.update(
|
|
(access) => (access.googleApiKey = e.currentTarget.value),
|
|
);
|
|
}}
|
|
/>
|
|
</>
|
|
) : null}
|
|
|
|
<div className={styles["auth-actions"]}>
|
|
<IconButton
|
|
text={Locale.Auth.Confirm}
|
|
type="primary"
|
|
onClick={goChat}
|
|
/>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|