diff --git a/src/screens/CreateScreen.js b/src/screens/CreateScreen.js index 8edbcd5..68c6569 100644 --- a/src/screens/CreateScreen.js +++ b/src/screens/CreateScreen.js @@ -63,7 +63,7 @@ function Create() { .then(response => { if (response.data.success) { dispatch(authLogin()); - history.push('/home'); + history.push('/success'); } else { toast({ title: 'An error occurred', diff --git a/src/screens/HomeScreen.js b/src/screens/HomeScreen.js index 59611cb..ea07683 100644 --- a/src/screens/HomeScreen.js +++ b/src/screens/HomeScreen.js @@ -1,6 +1,6 @@ import { Flex, Image, Spinner, Text } from '@chakra-ui/react'; import axios from 'axios'; -import { React, useState } from 'react'; +import { React, useEffect, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { Redirect } from 'react-router-dom'; import { authLogout } from '../features/auth/authSlice'; @@ -9,8 +9,7 @@ function QRCode() { const [url, setURL] = useState(null); const dispatch = useDispatch(); - if (!url) { - setURL("none"); + useEffect(() => { axios .get(`${process.env.REACT_APP_API_URL}/code`, { withCredentials: true }) .then(response => { @@ -23,10 +22,12 @@ function QRCode() { dispatch(authLogout()); } }); - } else if(url === "none"){ - return - }else { + }, []) + + if (url) { return ; + } else { + return ; } } @@ -43,8 +44,8 @@ function Home() { justifyContent="center" > - - This is your QR code. Show this to others to allow them to confirm a contact, or allow them to create an account! + + This is your QR code. Show this to others to allow them to confirm a contact, or allow them to create an account! ); diff --git a/src/screens/LoginScreen.js b/src/screens/LoginScreen.js index 7ddfa44..c7d0789 100644 --- a/src/screens/LoginScreen.js +++ b/src/screens/LoginScreen.js @@ -21,7 +21,7 @@ function Login() { const isAuthenticated = useSelector(state => state.auth.isAuthenticated); if (isAuthenticated) return ; - + const handleSubmit = e => { if (!email | !password) { toast({ @@ -74,7 +74,8 @@ function Login() { duration: 9000, isClosable: true, }); - }); + }) + .finally(() => { toast.closeAll(); }); e.preventDefault(); }; diff --git a/src/screens/SuccessScreen.js b/src/screens/SuccessScreen.js index e4960c5..feec185 100644 --- a/src/screens/SuccessScreen.js +++ b/src/screens/SuccessScreen.js @@ -13,7 +13,7 @@ function Success(){ > Success! - We have succesfully saved your contact! Stay safe out there! + We have succesfully saved your contact! Stay safe out there, and let others scan your QR code too!