Redirect to / if connected
This commit is contained in:
1 parent
5f8333e3f6
commit
0749bed223
2 files changed
+23
-2
No files matched your search
@@ -1,8 +1,21 @@
|
|||||||
import styles from "./LoginPage.module.css";
|
import styles from "./LoginPage.module.css";
|
||||||
import LoginForm from "../../components/loginform/loginForm.jsx";
|
import LoginForm from "../../components/loginform/loginForm.jsx";
|
||||||
import Background from "../../components/background/background.jsx";
|
import Background from "../../components/background/background.jsx";
|
||||||
|
import { useEffect, useContext } from "react";
|
||||||
|
import { AuthContext } from "../../contexts/auth/AuthContext.js";
|
||||||
|
import { useNavigate } from "react-router";
|
||||||
|
|
||||||
function LoginPage() {
|
function LoginPage() {
|
||||||
|
|
||||||
|
const { user, loading } = useContext(AuthContext)
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!loading && user) {
|
||||||
|
navigate("/");
|
||||||
|
}
|
||||||
|
}, [loading, user]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Background>
|
<Background>
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ import styles from "./RegisterPage.module.css";
|
|||||||
import Background from "../../components/background/background.jsx";
|
import Background from "../../components/background/background.jsx";
|
||||||
import Input from "../../components/ui/input/input.jsx";
|
import Input from "../../components/ui/input/input.jsx";
|
||||||
import Button from "../../components/ui/button/button.jsx";
|
import Button from "../../components/ui/button/button.jsx";
|
||||||
import { useState } from "react";
|
import {useContext, useEffect, useState} from "react";
|
||||||
import register from "../../utils/register.js";
|
import register from "../../utils/register.js";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
import {isNumber} from "chart.js/helpers";
|
import { AuthContext } from "../../contexts/auth/AuthContext.js";
|
||||||
|
|
||||||
|
|
||||||
function RegisterPage() {
|
function RegisterPage() {
|
||||||
@@ -19,6 +19,14 @@ function RegisterPage() {
|
|||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
const [lastName, setLastName] = useState("");
|
const [lastName, setLastName] = useState("");
|
||||||
|
|
||||||
|
const { user, loading } = useContext(AuthContext)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!loading && user) {
|
||||||
|
navigate("/");
|
||||||
|
}
|
||||||
|
}, [loading, user]);
|
||||||
|
|
||||||
async function handleSubmit(e) {
|
async function handleSubmit(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user