auth.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 resetAccessCode = () => { access.updateCode(""); access.updateToken(""); }; // Reset access code to empty string
  15. useEffect(() => {
  16. if (getClientConfig()?.isApp) {
  17. navigate(Path.Settings);
  18. }
  19. // eslint-disable-next-line react-hooks/exhaustive-deps
  20. }, []);
  21. return (
  22. <div className={styles["auth-page"]}>
  23. <div className={`no-dark ${styles["auth-logo"]}`}>
  24. <BotIcon />
  25. </div>
  26. <div className={styles["auth-title"]}>{Locale.Auth.Title}</div>
  27. <div className={styles["auth-tips"]}>{Locale.Auth.Tips}</div>
  28. <input
  29. className={styles["auth-input"]}
  30. type="password"
  31. placeholder={Locale.Auth.Input}
  32. value={access.accessCode}
  33. onChange={(e) => {
  34. access.updateCode(e.currentTarget.value);
  35. }}
  36. />
  37. <div className={styles["auth-tips"]}>{Locale.Auth.SubTips}</div>
  38. <input
  39. className={styles["auth-input"]}
  40. type="password"
  41. placeholder={Locale.Settings.Token.Placeholder}
  42. value={access.token}
  43. onChange={(e) => {
  44. access.updateToken(e.currentTarget.value);
  45. }}
  46. />
  47. <div className={styles["auth-actions"]}>
  48. <IconButton
  49. text={Locale.Auth.Confirm}
  50. type="primary"
  51. onClick={goHome}
  52. />
  53. <IconButton
  54. text={Locale.Auth.Later}
  55. onClick={() => {
  56. resetAccessCode();
  57. goHome();
  58. }}
  59. />
  60. </div>
  61. </div>
  62. );
  63. }