Skip to content

Instantly share code, notes, and snippets.

@zinedkaloc
Created August 8, 2022 11:54
Show Gist options
  • Save zinedkaloc/c580386bfde4f149b72a373c6f6a5d96 to your computer and use it in GitHub Desktop.
Save zinedkaloc/c580386bfde4f149b72a373c6f6a5d96 to your computer and use it in GitHub Desktop.
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