auth.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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(""); // 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-actions"]}>
  38. <IconButton
  39. text={Locale.Auth.Confirm}
  40. type="primary"
  41. onClick={goHome}
  42. />
  43. <IconButton text={Locale.Auth.Later} onClick={() => {
  44. resetAccessCode();
  45. goHome();
  46. }} />
  47. </div>
  48. </div>
  49. );
  50. }