Created
May 19, 2022 19:09
-
-
Save sourabhbagrecha/8a3fe3e96dcbc543085c2dc1ff888de1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Button } from '@mui/material' | |
import { useContext } from 'react'; | |
import { UserContext } from '../contexts/user.context'; | |
export default function Home() { | |
const { logOutUser } = useContext(UserContext); | |
// This function is called when the user clicks the "Logout" button. | |
const logOut = async () => { | |
try { | |
// Calling the logOutUser function from the user context. | |
const loggedOut = await logOutUser(); | |
// Now we will refresh the page, and the user will be logged out and | |
// redirected to the login page because of the <PrivateRoute /> component. | |
if (loggedOut) { | |
window.location.reload(true); | |
} | |
} catch (error) { | |
alert(error) | |
} | |
} | |
return ( | |
<> | |
<h1>Welcome to expengo</h1> | |
<Button variant="contained" onClick={logOut}>Logout</Button> | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment