Skip to content

Instantly share code, notes, and snippets.

@sourabhbagrecha
Created May 19, 2022 19:09
Show Gist options
  • Save sourabhbagrecha/8a3fe3e96dcbc543085c2dc1ff888de1 to your computer and use it in GitHub Desktop.
Save sourabhbagrecha/8a3fe3e96dcbc543085c2dc1ff888de1 to your computer and use it in GitHub Desktop.
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