Created
August 8, 2022 11:54
-
-
Save zinedkaloc/c580386bfde4f149b72a373c6f6a5d96 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 { useNavigate } from 'react-router'; | |
import { useAuth } from '../contexts/Auth'; | |
import { altogic } from '../helpers/altogic'; | |
export function Home() { | |
// Get current user and signOut function from context | |
const { user, setUser, setSession } = useAuth(); | |
const navigate = useNavigate(); | |
async function handleSignOut() { | |
// Ends user session | |
await altogic.auth.signOut(); | |
setUser(null); | |
setSession(null); | |
// Redirects the user to Login page | |
navigate('/login'); | |
} | |
return ( | |
<> | |
<div style={{ margin: '20px 20px' }}> | |
{/* Displays the user ID */} | |
<p>Welcome, {user?._id} !</p> | |
<span> | |
<p> | |
Your email verification status:{' '} | |
{user?.emailVerified ? 'Verified' : 'Not Verified'} | |
</p> | |
</span> | |
<pre>{user && JSON.stringify(user, null, 3)}</pre> | |
<button style={{ margin: '20px 20px' }} onClick={handleSignOut}> | |
Sign out | |
</button> | |
</div> | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment