Last active
December 28, 2021 15:42
-
-
Save skolhustick/c65d2396eac13ff2b7791f6d5d42cfc6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { useSession } from 'next-auth/react' | |
| import { useRouter } from 'next/router' | |
| export default function ClientProtected () { | |
| const router = useRouter() | |
| const { status } = useSession({ | |
| required: true, | |
| onUnauthenticated () { | |
| router.push('/api/auth/signin') | |
| } | |
| }) | |
| if (status === 'loading') { | |
| return 'Loading or not authenticated...' | |
| } | |
| return 'User is logged in' | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment