Skip to content

Commit

Permalink
fix:handle session not alive on frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Dami-18 committed Jul 13, 2024
1 parent bb96cbd commit 09c9c6a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const App: React.FC = () => {
return (
<>
<main>
<Toaster position="bottom-center" />
<Circles />
<div id="wrapper">
<div className="wrapper-item">
Expand All @@ -27,7 +28,6 @@ const App: React.FC = () => {
</div>
</main>
{openModal && <Modal closeModal={setOpenModal} />}
<Toaster position="bottom-center" />
</>
);
};
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/components/Electives.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useAppContext } from "../AppContext/AppContext";
import Spinner from "./Spinner";

const Electives: React.FC = () => {
const { user } = useAppContext();
const { user, logout } = useAppContext();
const [isBreadthDownloading, setIsBreadthDownloading] = useState(false);
const [isDepthDownloading, setIsDepthDownloading] = useState(false);
const getElective = async (elective: string) => {
Expand All @@ -27,8 +27,13 @@ const Electives: React.FC = () => {
body: formData.toString(),
});

const resData = await res.json();

if (!res.ok) {
toast.error("Some Error Occured. Please Try Again.");
if (res.status == 401)
if (resData.message == "Invalid Password" || resData.message == "Session isn't alive. PLease login again.")
logout();
return;
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/SecurityQueForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const SecurityQueForm: React.FC = () => {
return;
}
if (res.status == 401)
if (resData.message == "Invalid Password")
if (resData.message == "Invalid Password" || resData.message == "Session isn't alive. PLease login again.")
return setAuth((prev) => ({ ...prev, currentStep: 0 }));

if (res.status == 500) throw new Error(resData.message);
Expand Down Expand Up @@ -112,7 +112,7 @@ const SecurityQueForm: React.FC = () => {
return;
}
if (res.status == 401)
if (resData.message == "Invalid Password")
if (resData.message == "Invalid Password" || resData.message == "Session isn't alive. PLease login again.")
return setAuth((prev) => ({ ...prev, currentStep: 0 }));
if (resData.message == "Invalid OTP")
return setAuth((prev) => ({ ...prev, currentStep: 1 }));
Expand Down

0 comments on commit 09c9c6a

Please sign in to comment.