feat: pseudo login

This commit is contained in:
2025-04-16 15:00:44 +03:00
parent ae73b5d256
commit 5288637d19
3 changed files with 49 additions and 17 deletions

View File

@@ -5,28 +5,52 @@ import { UrlsTitle } from "@/enums/urls";
import { useAppContext } from "@/providers/AuthProvider";
import { FunctionComponent } from "preact";
import { useLocation } from "preact-iso";
import "preact/debug";
import { useRef, useState } from "preact/hooks";
import classes from "./login.module.scss";
const testUser = {
login: "test",
password: "test",
};
const LoginPage: FunctionComponent = () => {
const { isLoggedIn } = useAppContext();
const { route } = useLocation();
return (
const loginRef = useRef<HTMLInputElement | null>(null);
const passwordRef = useRef<HTMLInputElement | null>(null);
const [loginError, setLoginError] = useState("");
const [passwordError, setPasswordError] = useState("");
const login = async () => {
if (!loginRef.current || !passwordRef.current) return;
setLoginError("");
setPasswordError("");
if (!loginRef.current.value.length || !passwordRef.current.value.length) {
if (!loginRef.current.value.length) setLoginError("Введите логин");
if (!passwordRef.current.value.length) setPasswordError("Введите пароль");
return;
}
if (loginRef.current.value !== testUser.login || passwordRef.current.value !== testUser.password) {
setLoginError("Неправильный логин или пароль");
return;
}
isLoggedIn.value = true;
localStorage.setItem("loggedIn", "true");
route("/profile/tasks", true);
};
if (isLoggedIn.value) route("/profile/tasks", true);
return !isLoggedIn.value ? (
<div class={classes.login_container}>
<div class={classes.login_card}>
<p class={classes.login_card_name}>Антихвост</p>
<Input placeholder="Логин" textAlign="center" />
<Input isPassword placeholder="Пароль" textAlign="center" />
<Button
color="secondary"
onClick={() => {
isLoggedIn.value = true;
localStorage.setItem("loggedIn", "true");
route("/profile/tasks", true);
}}
>
<Input placeholder="Логин" textAlign="center" textRef={loginRef} error={loginError} />
<Input isPassword placeholder="Пароль" textAlign="center" textRef={passwordRef} error={passwordError} />
<Button color="secondary" onClick={login}>
Войти
</Button>
</div>
</div>
) : (
<p>Redirecting...</p>
);
};