auth.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import styles from "./auth.module.scss";
  2. import { IconButton } from "./button";
  3. import { useNavigate } from "react-router-dom";
  4. import { Path, SAAS_CHAT_URL } 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 goSaas = () => window.open(SAAS_CHAT_URL);
  16. const resetAccessCode = () => {
  17. accessStore.update((access) => {
  18. access.openaiApiKey = "";
  19. access.accessCode = "";
  20. });
  21. }; // Reset access code to empty string
  22. useEffect(() => {
  23. if (getClientConfig()?.isApp) {
  24. navigate(Path.Settings);
  25. }
  26. // eslint-disable-next-line react-hooks/exhaustive-deps
  27. }, []);
  28. return (
  29. <div className={styles["auth-page"]}>
  30. <div className={`no-dark ${styles["auth-logo"]}`}>
  31. <BotIcon />
  32. </div>
  33. <div className={styles["auth-title"]}>{Locale.Auth.Title}</div>
  34. <div className={styles["auth-tips"]}>{Locale.Auth.Tips}</div>
  35. <input
  36. className={styles["auth-input"]}
  37. type="password"
  38. placeholder={Locale.Auth.Input}
  39. value={accessStore.accessCode}
  40. onChange={(e) => {
  41. accessStore.update(
  42. (access) => (access.accessCode = e.currentTarget.value),
  43. );
  44. }}
  45. />
  46. {!accessStore.hideUserApiKey ? (
  47. <>
  48. <div className={styles["auth-tips"]}>{Locale.Auth.SubTips}</div>
  49. <input
  50. className={styles["auth-input"]}
  51. type="password"
  52. placeholder={Locale.Settings.Access.OpenAI.ApiKey.Placeholder}
  53. value={accessStore.openaiApiKey}
  54. onChange={(e) => {
  55. accessStore.update(
  56. (access) => (access.openaiApiKey = e.currentTarget.value),
  57. );
  58. }}
  59. />
  60. <input
  61. className={styles["auth-input-second"]}
  62. type="password"
  63. placeholder={Locale.Settings.Access.Google.ApiKey.Placeholder}
  64. value={accessStore.googleApiKey}
  65. onChange={(e) => {
  66. accessStore.update(
  67. (access) => (access.googleApiKey = e.currentTarget.value),
  68. );
  69. }}
  70. />
  71. </>
  72. ) : null}
  73. <div className={styles["auth-actions"]}>
  74. <IconButton
  75. text={Locale.Auth.Confirm}
  76. type="primary"
  77. onClick={goChat}
  78. />
  79. <IconButton
  80. text={Locale.Auth.SaasTips}
  81. onClick={() => {
  82. goSaas();
  83. }}
  84. />
  85. </div>
  86. </div>
  87. );
  88. }