Skip to content

Commit cd6d366

Browse files
committed
fix(rbac): verifying the renders
1 parent 20ad8b8 commit cd6d366

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

example/ts-fire-example/package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/ts-fire-example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"firebase": "^8.7.0",
1313
"next": "11.0.1",
14-
"next-shield": "^2.0.3",
14+
"next-shield": "^2.0.4",
1515
"react": "17.0.2",
1616
"react-dom": "17.0.2",
1717
"react-firebase-hooks": "^3.0.4",

src/components/NextShield.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,17 @@ export function NextShield<
6767

6868
useEffect(() => {
6969
if (!isAuth && !isLoading && pathIsPrivate) replace(loginRoute)
70-
if (isAuth && !isLoading && pathIsPublic) replace(access)
71-
if (isAuth && !isLoading && !pathIsHybrid && !pathIsAuthorized) replace(access)
70+
if (isAuth && !isLoading && pathIsPublic) {
71+
console.log('redirected to private route', { access, pathIsAuthorized })
72+
replace(access)
73+
}
74+
if (isAuth && userRole && !isLoading && !pathIsHybrid && !pathIsAuthorized) {
75+
console.log('redirected to granted route', { access, pathIsAuthorized })
76+
replace(access)
77+
}
7278
}, [
7379
replace,
80+
userRole,
7481
access,
7582
isAuth,
7683
isLoading,

0 commit comments

Comments
 (0)