Skip to content

Commit

Permalink
Merge pull request #49 from OZimbres/othon/fix-login-chat-redirect
Browse files Browse the repository at this point in the history
[fix]: do not redirect to account when in chat
  • Loading branch information
LoriaLawrenceZ authored Aug 31, 2024
2 parents 454d6f6 + 1f1fd5c commit 7f16b04
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/components/AuthenticationCard/SignIn.jsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import "../../style/Authentication/AuthenticationCard/AuthenticationCard.css";
import { IoIosClose } from "react-icons/io";
import useAuthenticationContext from "../../hook/Authentication/useAuthenticationContext.jsx";
import { useNavigate } from "react-router-dom";
import { useLocation, useNavigate } from "react-router-dom";
import { useEffect, useState } from "react";

function SignIn() {
const navigate = useNavigate(); // Navega para rota especificada
const location = useLocation();

const [email, setEmail] = useState("");
const [password, setPassword] = useState("");

const {
setAuthedUser,

isSignInVisible, setIsSignInVisible,
isSignUpVisible, setIsSignUpVisible,
isSignInVisible,
setIsSignInVisible,
setIsSignUpVisible,
isShowSignInCloseBtn,

setIsModalVisible,

registeredUsersList,

setHasInteractedOnce,
isSignInErrorAlertVisible, setIsSignInErrorAlertVisible,
isSignInSuccessfulAlertVisible, setIsSignInSuccessfulAlertVisible,
setIsTesterAlertVisible
isSignInErrorAlertVisible,
setIsSignInErrorAlertVisible,
isSignInSuccessfulAlertVisible,
setIsSignInSuccessfulAlertVisible,
setIsTesterAlertVisible,
} = useAuthenticationContext();

const handleCloseBtn = () => {
Expand All @@ -41,13 +42,15 @@ function SignIn() {
event.preventDefault();

const user = findUser(email);

if (user && user.password === password) {
setIsSignInSuccessfulAlertVisible(true);
setAuthedUser({ ...user, password: undefined });
setIsSignInVisible(false);
setIsModalVisible(false);
navigate("/account");
if (location.pathname !== "/chat") {
navigate("/account");
}
} else {
setIsSignInErrorAlertVisible(true);
setAuthedUser(undefined);
Expand Down Expand Up @@ -77,7 +80,7 @@ function SignIn() {
return () => clearTimeout(timer);
}
}, [isSignInErrorAlertVisible]);

useEffect(() => {
if (isSignInSuccessfulAlertVisible) {
const timer = setTimeout(() => {
Expand Down

0 comments on commit 7f16b04

Please sign in to comment.