auth WIP 2
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
const Dashboard = () => {
|
||||
return (
|
||||
<div>
|
||||
<h2>Dashboard</h2>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Dashboard;
|
||||
|
||||
@@ -1,11 +1,23 @@
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import useAuth from "../../auth/auth";
|
||||
|
||||
import { Link } from 'react-router-dom';
|
||||
import logout from "../../auth/logout"
|
||||
import useLogout from "../../auth/logout"
|
||||
|
||||
|
||||
const Home = () => {
|
||||
const { setToken } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleLogout = () => {
|
||||
setToken(null);
|
||||
navigate("/login");
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2>Home</h2>
|
||||
<button onClick={logout()}>
|
||||
<button onClick={handleLogout}>
|
||||
Logout
|
||||
</button>
|
||||
<nav>
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
9
src/pages/settings/settings.tsx
Normal file
9
src/pages/settings/settings.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
const Settings = () => {
|
||||
return (
|
||||
<div>
|
||||
<h2>Settings</h2>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Settings;
|
||||
Reference in New Issue
Block a user