#13 Got auth logic working

This commit was merged in pull request #19.
This commit is contained in:
2023-03-19 14:55:51 -04:00
parent 851a784aaa
commit 8b9bc96b93
5 changed files with 66 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
import React, { useState } from "react";
import React, { useContext, useEffect, useState } from "react";
import { Button, Col, Container, Form, Row, Alert } from "react-bootstrap";
import MyNavbar from "../components/MyNavbar";
import UserContext from "../contexts/UserContext";
import { makeRequest } from "../utils.ts";
const LoginPage = () => {
@@ -8,6 +9,19 @@ const LoginPage = () => {
const [password, setPassword] = useState("");
const [error, setError] = useState(null);
const { currentUser, setCurrentUser } = useContext(UserContext);
useEffect(() => {
console.log(currentUser);
if (currentUser?.id) {
gotoHome();
}
}, [currentUser]);
const gotoHome = () => {
window.location.href = "/";
};
const sendLoginRequest = async (e) => {
e?.preventDefault();
await makeRequest({
@@ -21,8 +35,7 @@ const LoginPage = () => {
setError(data);
return;
}
console.log(data);
window.location.href = "/";
setCurrentUser(data);
});
};