From 851a784aaae891dd20d5aa43a8c132d5740c2c58 Mon Sep 17 00:00:00 2001 From: Jagraj Aulakh Date: Sun, 19 Mar 2023 02:22:23 -0400 Subject: [PATCH] #13 Error alert formatting --- frontend/src/pages/HomePage.jsx | 9 +++++++++ frontend/src/pages/LoginPage.jsx | 12 ++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/HomePage.jsx b/frontend/src/pages/HomePage.jsx index 527d63a..f016608 100644 --- a/frontend/src/pages/HomePage.jsx +++ b/frontend/src/pages/HomePage.jsx @@ -1,7 +1,16 @@ +import { useEffect } from "react"; import { Container } from "react-bootstrap"; import MyNavbar from "../components/MyNavbar"; const HomePage = () => { + {/*{current_user} = use context*/} + const current_user = null; + + useEffect(()=>{ + if (!current_user) { + window.location.replace("/login"); + } + }, []); return (
diff --git a/frontend/src/pages/LoginPage.jsx b/frontend/src/pages/LoginPage.jsx index 14672bc..220eb56 100644 --- a/frontend/src/pages/LoginPage.jsx +++ b/frontend/src/pages/LoginPage.jsx @@ -1,5 +1,5 @@ import React, { useState } from "react"; -import { Button, Col, Container, Form, Row, Alert} from "react-bootstrap"; +import { Button, Col, Container, Form, Row, Alert } from "react-bootstrap"; import MyNavbar from "../components/MyNavbar"; import { makeRequest } from "../utils.ts"; @@ -9,7 +9,7 @@ const LoginPage = () => { const [error, setError] = useState(null); const sendLoginRequest = async (e) => { - e.preventDefault(); + e?.preventDefault(); await makeRequest({ url: "http://localhost:5000/login", method: "POST", @@ -29,8 +29,12 @@ const LoginPage = () => { return ( - { error && ( - ERROR! {error.message} + {error && ( + + + {error.message} + + )}