Skip to content

Instantly share code, notes, and snippets.

@skolhustick
Last active December 28, 2021 15:42
Show Gist options
  • Save skolhustick/c65d2396eac13ff2b7791f6d5d42cfc6 to your computer and use it in GitHub Desktop.
Save skolhustick/c65d2396eac13ff2b7791f6d5d42cfc6 to your computer and use it in GitHub Desktop.
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