auth.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. import LeftIcon from "@/app/icons/left.svg";
  11. export function AuthPage() {
  12. const navigate = useNavigate();
  13. const accessStore = useAccessStore();
  14. const goHome = () => navigate(Path.Home);
  15. const goChat = () => navigate(Path.Chat);
  16. const goSaas = () => {
  17. window.location.href = SAAS_CHAT_URL;
  18. };
  19. const resetAccessCode = () => {
  20. accessStore.update((access) => {
  21. access.openaiApiKey = "";
  22. access.accessCode = "";
  23. });
  24. }; // Reset access code to empty string
  25. useEffect(() => {
  26. if (getClientConfig()?.isApp) {
  27. navigate(Path.Settings);
  28. }
  29. // eslint-disable-next-line react-hooks/exhaustive-deps
  30. }, []);
  31. return (
  32. <div className={styles["auth-page"]}>
  33. <div className={styles["auth-header"]}>
  34. <IconButton
  35. icon={<LeftIcon />}
  36. text={Locale.Auth.Return}
  37. onClick={() => navigate(Path.Home)}
  38. ></IconButton>
  39. </div>
  40. <div className={`no-dark ${styles["auth-logo"]}`}>
  41. <BotIcon />
  42. </div>
  43. <div className={styles["auth-title"]}>{Locale.Auth.Title}</div>
  44. <div className={styles["auth-tips"]}>{Locale.Auth.Tips}</div>
  45. <input
  46. className={styles["auth-input"]}
  47. type="password"
  48. placeholder={Locale.Auth.Input}
  49. value={accessStore.accessCode}
  50. onChange={(e) => {
  51. accessStore.update(
  52. (access) => (access.accessCode = e.currentTarget.value),
  53. );
  54. }}
  55. />
  56. {!accessStore.hideUserApiKey ? (
  57. <>
  58. <div className={styles["auth-tips"]}>{Locale.Auth.SubTips}</div>
  59. <input
  60. className={styles["auth-input"]}
  61. type="password"
  62. placeholder={Locale.Settings.Access.OpenAI.ApiKey.Placeholder}
  63. value={accessStore.openaiApiKey}
  64. onChange={(e) => {
  65. accessStore.update(
  66. (access) => (access.openaiApiKey = e.currentTarget.value),
  67. );
  68. }}
  69. />
  70. <input
  71. className={styles["auth-input-second"]}
  72. type="password"
  73. placeholder={Locale.Settings.Access.Google.ApiKey.Placeholder}
  74. value={accessStore.googleApiKey}
  75. onChange={(e) => {
  76. accessStore.update(
  77. (access) => (access.googleApiKey = e.currentTarget.value),
  78. );
  79. }}
  80. />
  81. </>
  82. ) : null}
  83. <div className={styles["auth-actions"]}>
  84. <IconButton
  85. text={Locale.Auth.Confirm}
  86. type="primary"
  87. onClick={goChat}
  88. />
  89. <IconButton
  90. text={Locale.Auth.SaasTips}
  91. onClick={() => {
  92. goSaas();
  93. }}
  94. />
  95. </div>
  96. </div>
  97. );
  98. }