redir fixes + 404 style fixes
This commit is contained in:
@ -27,7 +27,6 @@ const PrivateRoute = () => {
|
||||
const [checked, setChecked] = useState(false);
|
||||
const [isValid, setIsValid] = useState(false);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const checkAuth = async () => {
|
||||
if (!token) {
|
||||
@ -85,7 +84,7 @@ function App() {
|
||||
<Route path='/settings' element={<Settings />} />
|
||||
</Route>
|
||||
|
||||
<Route path="*" element={<div>404</div>} />
|
||||
<Route path="*" element={<h1 className="not-found">404<br/>Not Found</h1>} />
|
||||
</Routes>
|
||||
</Router>
|
||||
</>
|
||||
|
||||
@ -31,3 +31,10 @@ body {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.not-found {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
@ -13,14 +13,15 @@ const Login = () => {
|
||||
const { setToken } = useAuth();
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const searchPath = new URLSearchParams(location.search);
|
||||
const redirectPath = searchPath.get('to') || "/";
|
||||
|
||||
const [usernameEmpty, setUsernameEmpty] = useState(false);
|
||||
const [passwordEmpty, setPasswordEmpty] = useState(false);
|
||||
|
||||
const from = location.state?.from?.pathname || "/";
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
@ -35,7 +36,7 @@ const Login = () => {
|
||||
if ((username === "admin" && password === "1234") || (username === "a" && password === "a")) {
|
||||
const token = "todo.jwt.token";
|
||||
setToken(token);
|
||||
navigate(from, { replace: true });
|
||||
navigate(redirectPath, { replace: true });
|
||||
} else {
|
||||
toast.error("Wrong login or password");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user