auth.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. {/* <input*/}
  60. {/* className={styles["auth-input"]}*/}
  61. {/* type="password"*/}
  62. {/* placeholder={Locale.Settings.Access.Google.ApiKey.Placeholder}*/}
  63. {/* value={accessStore.googleApiKey}*/}
  64. {/* onChange={(e) => {*/}
  65. {/* accessStore.update(*/}
  66. {/* (access) => (access.googleApiKey = e.currentTarget.value),*/}
  67. {/* );*/}
  68. {/* }}*/}
  69. {/* />*/}
  70. {/* </>*/}
  71. {/*) : null}*/}
  72. <div className={styles["auth-actions"]}>
  73. <IconButton
  74. text={Locale.Auth.Confirm}
  75. type="primary"
  76. onClick={goChat}
  77. />
  78. <IconButton
  79. text={Locale.Auth.Later}
  80. onClick={() => {
  81. resetAccessCode();
  82. goHome();
  83. }}
  84. />
  85. </div>
  86. </div>
  87. );
  88. }