Skip to content

Commit 80fad2a

Browse files
authored
Merge pull request #78 from leonardoOluz/fetchData
feat: ✨ Adiciona lógica de redirecionamento no componente Lo…
2 parents bacd0ea + 4eededd commit 80fad2a

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/hooks/useCheckRotas.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ const useCheckRotas = () => {
1212
const navigate = useNavigate();
1313
const location = useLocation();
1414

15+
useEffect(() => {
16+
if (!isLogado) {
17+
navigate("/login");
18+
}
19+
}, [isLogado, navigate]);
20+
1521
useEffect(() => {
1622
const privatePrefixes = [
1723
`/${CheckoutSteps.CHECKOUT}`,
@@ -22,11 +28,8 @@ const useCheckRotas = () => {
2228
privatePrefixes.some((prefix) => location.pathname.startsWith(prefix))
2329
) {
2430
dispatch(checkAuthenticatedUser());
25-
if (!isLogado) {
26-
navigate("/login");
27-
}
2831
}
29-
}, [isLogado, navigate, location.pathname, dispatch]);
32+
}, [navigate, location.pathname, dispatch]);
3033
};
3134

3235
export default useCheckRotas;

src/pages/login/index.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@ import Section from "@/components/Section";
22
import Typography from "@/components/Typography";
33
import { thema } from "@/styles/thema";
44
import FormLogin from "./FormLogin";
5-
import { Link } from "react-router-dom";
5+
import { Link, useNavigate } from "react-router-dom";
66
import useWriteSlowly from "@/hooks/useWriteSlowly";
77
import { DivFadeInForm } from "@/styles/forms";
8+
import { useEffect } from "react";
9+
import { RootState } from "@/types/store";
10+
import { useSelector } from "react-redux";
811
const title = "Entre com sua conta!";
912
const Login = () => {
1013
const writeTitle = useWriteSlowly(title);
14+
const navigate = useNavigate();
15+
const { isLogado } = useSelector((state: RootState) => state.usuario);
16+
17+
useEffect(() => {
18+
if (isLogado) {
19+
navigate(-1);
20+
}
21+
}, [navigate, isLogado]);
1122

1223
return (
1324
<Section classNameSection="secao login">

0 commit comments

Comments
 (0)