@@ -1,16 +1,17 @@
|
||||
import { useEffect } from "react";
|
||||
import { useContext, useEffect } from "react";
|
||||
import { Container } from "react-bootstrap";
|
||||
import MyNavbar from "../components/MyNavbar";
|
||||
import UserContext from "../contexts/UserContext";
|
||||
|
||||
const HomePage = () => {
|
||||
{/*{current_user} = use context*/}
|
||||
const current_user = null;
|
||||
const { currentUser } = useContext(UserContext);
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentUser?.id) {
|
||||
window.location.replace("/login");
|
||||
}
|
||||
}, [currentUser]);
|
||||
|
||||
useEffect(()=>{
|
||||
if (!current_user) {
|
||||
window.location.replace("/login");
|
||||
}
|
||||
}, []);
|
||||
return (
|
||||
<div>
|
||||
<MyNavbar />
|
||||
|
||||
@@ -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