diff --git a/example/ts-fire-example/components/router/Shield.tsx b/example/ts-fire-example/components/router/Shield.tsx index 4c5e95b..d46f4e5 100644 --- a/example/ts-fire-example/components/router/Shield.tsx +++ b/example/ts-fire-example/components/router/Shield.tsx @@ -43,7 +43,7 @@ export function Shield({ children }: Props) { accessRoute: '/dashboard', }, }, - userRole: value?.role as string, + userRole: value?.role ?? 'USER', } if (error) return

{error}

diff --git a/example/ts-fire-example/package-lock.json b/example/ts-fire-example/package-lock.json index 4ec2e1f..7ad3a12 100644 --- a/example/ts-fire-example/package-lock.json +++ b/example/ts-fire-example/package-lock.json @@ -3040,9 +3040,9 @@ } }, "next-shield": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/next-shield/-/next-shield-2.0.6.tgz", - "integrity": "sha512-6VIRPYbY5ot++6d6+2noikEqZn95Tz1JMrVC9lyxy74DhZd/IaB8L9eXAH2nRmSm3uACq8qqOaUZVY7qaq777w==" + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/next-shield/-/next-shield-2.0.7.tgz", + "integrity": "sha512-TIXu2WS63LjZOLlnSucUCw7UDDgL2OVQhdlUrFW6QDfjis17dfeu4GezMmj8nj0sGjO8eZaTZBVMc9vGf+VinQ==" }, "node-fetch": { "version": "2.6.1", diff --git a/example/ts-fire-example/package.json b/example/ts-fire-example/package.json index 8aa989f..d33869e 100644 --- a/example/ts-fire-example/package.json +++ b/example/ts-fire-example/package.json @@ -11,7 +11,7 @@ "dependencies": { "firebase": "^8.7.0", "next": "11.0.1", - "next-shield": "^2.0.6", + "next-shield": "^2.0.7", "react": "17.0.2", "react-dom": "17.0.2", "react-firebase-hooks": "^3.0.4", diff --git a/src/components/NextShield.tsx b/src/components/NextShield.tsx index 6dc54d6..97ec426 100644 --- a/src/components/NextShield.tsx +++ b/src/components/NextShield.tsx @@ -66,20 +66,18 @@ export function NextShield< const access = getAccessRoute(RBAC, userRole, accessRoute, loginRoute) useEffect(() => { - if (!isAuth && !isLoading && pathIsPrivate) { - console.log({ - userRole, - access, - isAuth, - isLoading, - loginRoute, - pathIsPrivate, - pathIsPublic, - pathIsHybrid, - pathIsAuthorized, - }) - replace(loginRoute) - } + console.log({ + userRole, + access, + isAuth, + isLoading, + loginRoute, + pathIsPrivate, + pathIsPublic, + pathIsHybrid, + pathIsAuthorized, + }) + if (!isAuth && !isLoading && pathIsPrivate) replace(loginRoute) if (isAuth && !isLoading && pathIsPublic) replace(access) if (isAuth && userRole && !isLoading && !pathIsHybrid && !pathIsAuthorized) replace(access)