How to redirect when user ~is~ authenticated
So there's lots of documentation about protecting routes, and there's also ways within the useSession hook to perform an action if the user isn't authenticated. But is there a way to redirect if they ~are~ authenticated? I'd like to avoid doing something like:
Because I get a react error about the component not finishing rendering. Is this the only way to do it or can i do something with next on the backend?
const { data: sessionData, status } = useSession({ required: true })
const router = useRouter()
if (status === 'authenticated') {
void router.push('/quiz/results/success')
}
Because I get a react error about the component not finishing rendering. Is this the only way to do it or can i do something with next on the backend?