Forked from sourabhbagrecha/expengo-src-pages-Home.page.js
Created
June 5, 2022 14:29
-
-
Save ayowilfred95/b9664d5a4a9362d2b13e48d4c5e46200 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