auth.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import styles from "./auth.module.scss";
  2. import { IconButton } from "./button";
  3. import { useNavigate } from "react-router-dom";
  4. import { Path } from "../constant";
  5. import { useAccessStore } from "../store";
  6. import Locale from "../locales";
  7. import BotIcon from "../icons/bot.svg";
  8. import { useEffect } from "react";
  9. import { getClientConfig } from "../config/client";
  10. export function AuthPage() {
  11. const navigate = useNavigate();
  12. const access = useAccessStore();
  13. const goHome = () => navigate(Path.Home);
  14. const goChat = () => navigate(Path.Chat);
  15. const resetAccessCode = () => { access.updateCode(""); access.updateToken(""); }; // Reset access code to empty string
  16. useEffect(() => {
  17. if (getClientConfig()?.isApp) {
  18. navigate(Path.Settings);
  19. }
  20. // eslint-disable-next-line react-hooks/exhaustive-deps
  21. }, []);
  22. return (
  23. <div className={styles["auth-page"]}>
  24. <div className={`no-dark ${styles["auth-logo"]}`}>
  25. <BotIcon />
  26. </div>
  27. <div className={styles["auth-title"]}>{Locale.Auth.Title}</div>
  28. <div className={styles["auth-tips"]}>{Locale.Auth.Tips}</div>
  29. <input
  30. className={styles["auth-input"]}
  31. type="password"
  32. placeholder={Locale.Auth.Input}
  33. value={access.accessCode}
  34. onChange={(e) => {
  35. access.updateCode(e.currentTarget.value);
  36. }}
  37. />
  38. {!access.hideUserApiKey ? (
  39. <>
  40. <div className={styles["auth-tips"]}>{Locale.Auth.SubTips}</div>
  41. <input
  42. className={styles["auth-input"]}
  43. type="password"
  44. placeholder={Locale.Settings.Token.Placeholder}
  45. value={access.token}
  46. onChange={(e) => {
  47. access.updateToken(e.currentTarget.value);
  48. }}
  49. />
  50. </>
  51. ) : null}
  52. <div className={styles["auth-actions"]}>
  53. <IconButton
  54. text={Locale.Auth.Confirm}
  55. type="primary"
  56. onClick={goChat}
  57. />
  58. <IconButton
  59. text={Locale.Auth.Later}
  60. onClick={() => {
  61. resetAccessCode();
  62. goHome();
  63. }}
  64. />
  65. </div>
  66. </div>
  67. );
  68. }