#13-login-page #19

Merged
juggy1233 merged 4 commits from #13-login-page into master 2023-03-19 14:59:33 -04:00
2 changed files with 17 additions and 4 deletions
Showing only changes of commit 851a784aaa - Show all commits

View File

@@ -1,7 +1,16 @@
import { useEffect } from "react";
import { Container } from "react-bootstrap"; import { Container } from "react-bootstrap";
import MyNavbar from "../components/MyNavbar"; import MyNavbar from "../components/MyNavbar";
const HomePage = () => { const HomePage = () => {
{/*{current_user} = use context*/}
const current_user = null;
useEffect(()=>{
if (!current_user) {
window.location.replace("/login");
}
}, []);
return ( return (
<div> <div>
<MyNavbar /> <MyNavbar />

View File

@@ -1,5 +1,5 @@
import React, { useState } from "react"; 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 MyNavbar from "../components/MyNavbar";
import { makeRequest } from "../utils.ts"; import { makeRequest } from "../utils.ts";
@@ -9,7 +9,7 @@ const LoginPage = () => {
const [error, setError] = useState(null); const [error, setError] = useState(null);
const sendLoginRequest = async (e) => { const sendLoginRequest = async (e) => {
e.preventDefault(); e?.preventDefault();
await makeRequest({ await makeRequest({
url: "http://localhost:5000/login", url: "http://localhost:5000/login",
method: "POST", method: "POST",
@@ -29,8 +29,12 @@ const LoginPage = () => {
return ( return (
<React.Fragment> <React.Fragment>
<MyNavbar /> <MyNavbar />
{ error && ( {error && (
<Alert variant="danger" className="m-4 mx-auto w-25">ERROR! {error.message}</Alert> <Container>
<Alert variant="danger" className="m-4 mx-auto w-50 text-center">
{error.message}
</Alert>
</Container>
)} )}
<Container className="p-5"> <Container className="p-5">
<Form onSubmit={sendLoginRequest}> <Form onSubmit={sendLoginRequest}>