auth WIP 2
This commit is contained in:
@ -2,24 +2,26 @@ import { useState } from "react";
|
||||
import { useNavigate, useLocation } from "react-router-dom";
|
||||
import useAuth from "../../auth/auth";
|
||||
|
||||
|
||||
const Login = () => {
|
||||
const { setToken: setAuth } = useAuth();
|
||||
const { setToken } = useAuth();
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
const from = location.state?.from?.pathname || "/home";
|
||||
const from = location.state?.from?.pathname || "/";
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
// TODO: request to API
|
||||
if (username === "admin" && password === "1234") {
|
||||
setAuth(true);
|
||||
const token = "todo.jwt.token";
|
||||
setToken(token);
|
||||
navigate(from, { replace: true });
|
||||
} else {
|
||||
alert("Неверный логин или пароль");
|
||||
alert("Wrong login or password");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user