From 892df5275548b85a6f979fb2cf76dedb28954aa0 Mon Sep 17 00:00:00 2001 From: "Rayyan (Rayy)" Date: Tue, 19 Sep 2023 10:58:05 +0000 Subject: [PATCH] Redirect to homepage once user registers --- src/pages/Signup.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pages/Signup.js b/src/pages/Signup.js index 744eb68..d1bb9c8 100644 --- a/src/pages/Signup.js +++ b/src/pages/Signup.js @@ -5,6 +5,7 @@ import Col from 'react-bootstrap/Col'; import Button from "react-bootstrap/Button"; import {useState, useEffect, useContext} from 'react'; import { AuthContext } from "../contexts/AuthContext"; +import {useNavigate} from 'react-router-dom'; export function Signup ( props ) { const[username,setUsername] = useState('') @@ -21,6 +22,14 @@ export function Signup ( props ) { props.handler( useremail, userpassword ) } + const navigate = useNavigate() + + useEffect( () => { + if( auth ) { + // go to home page + navigate("/") + } + }, [auth]) useEffect( () => { if( username.length >= 4 ) { setValidusername(true) @@ -93,4 +102,4 @@ export function Signup ( props ) { ) -} \ No newline at end of file + }