@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user