Improved the overall redirection of the login page

This commit is contained in:
Tiago Ribeiro
2024-01-17 14:25:37 +00:00
parent c02a6a01f4
commit 63d2baf35f
2 changed files with 37 additions and 4 deletions

View File

@@ -15,10 +15,10 @@ export default function useUser({redirectTo = "", redirectIfFound = false} = {})
if (!redirectTo || !user) return;
if (
// If redirectTo is set, redirect if the user was not found.
(redirectTo && !redirectIfFound && (!user || (user && !user.isVerified))) ||
// If redirectIfFound is also set, redirect if the user was found
(redirectIfFound && user && user.isVerified)
(redirectIfFound && user && user.isVerified) ||
// If redirectTo is set, redirect if the user was not found.
(redirectTo && !redirectIfFound && (!user || (user && !user.isVerified)))
) {
Router.push(redirectTo);
}