auth.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 accessStore = useAccessStore();
  13. const goHome = () => navigate(Path.Home);
  14. const goChat = () => navigate(Path.Chat);
  15. const resetAccessCode = () => {
  16. accessStore.update((access) => {
  17. access.openaiApiKey = "";
  18. access.accessCode = "";
  19. });
  20. }; // Reset access code to empty string
  21. useEffect(() => {
  22. if (getClientConfig()?.isApp) {
  23. navigate(Path.Settings);
  24. }
  25. // eslint-disable-next-line react-hooks/exhaustive-deps
  26. }, []);
  27. return (
  28. <div className={styles["auth-page"]}>
  29. <div className={`no-dark ${styles["auth-logo"]}`}>
  30. <BotIcon />
  31. </div>
  32. <div className={styles["auth-title"]}>{Locale.Auth.Title}</div>
  33. <div className={styles["auth-tips"]}>{Locale.Auth.Tips}</div>
  34. <input
  35. className={styles["auth-input"]}
  36. type="password"
  37. placeholder={Locale.Auth.Input}
  38. value={accessStore.accessCode}
  39. onChange={(e) => {
  40. accessStore.update(
  41. (access) => (access.accessCode = e.currentTarget.value),
  42. );
  43. }}
  44. />
  45. {!accessStore.hideUserApiKey ? (
  46. <>
  47. <div className={styles["auth-tips"]}>{Locale.Auth.SubTips}</div>
  48. <input
  49. className={styles["auth-input"]}
  50. type="password"
  51. placeholder={Locale.Settings.Access.OpenAI.ApiKey.Placeholder}
  52. value={accessStore.openaiApiKey}
  53. onChange={(e) => {
  54. accessStore.update(
  55. (access) => (access.openaiApiKey = e.currentTarget.value),
  56. );
  57. }}
  58. />
  59. </>
  60. ) : null}
  61. <div className={styles["auth-actions"]}>
  62. <IconButton
  63. text={Locale.Auth.Confirm}
  64. type="primary"
  65. onClick={goChat}
  66. />
  67. <IconButton
  68. text={Locale.Auth.Later}
  69. onClick={() => {
  70. resetAccessCode();
  71. goHome();
  72. }}
  73. />
  74. </div>
  75. </div>
  76. );
  77. }