Skip to content

Commit 538f41e

Browse files
committed
fix(rbac): checking rerenders
1 parent 46dab1d commit 538f41e

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

example/ts-fire-example/components/router/Shield.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function Shield({ children }: Props) {
4343
accessRoute: '/dashboard',
4444
},
4545
},
46-
userRole: value?.role ?? 'USER',
46+
userRole: value?.role as string,
4747
}
4848

4949
if (error) return <p>{error}</p>

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.7",
14+
"next-shield": "^2.0.8",
1515
"react": "17.0.2",
1616
"react-dom": "17.0.2",
1717
"react-firebase-hooks": "^3.0.4",

src/components/NextShield.tsx

+15-12
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,19 @@ export function NextShield<
6565
RBAC && userRole && verifyPath(RBAC[userRole].grantedRoutes, pathname)
6666
const access = getAccessRoute(RBAC, userRole, accessRoute, loginRoute)
6767

68+
console.log({
69+
userRole,
70+
access,
71+
isAuth,
72+
isLoading,
73+
loginRoute,
74+
pathIsPrivate,
75+
pathIsPublic,
76+
pathIsHybrid,
77+
pathIsAuthorized,
78+
})
79+
6880
useEffect(() => {
69-
console.log({
70-
userRole,
71-
access,
72-
isAuth,
73-
isLoading,
74-
loginRoute,
75-
pathIsPrivate,
76-
pathIsPublic,
77-
pathIsHybrid,
78-
pathIsAuthorized,
79-
})
8081
if (!isAuth && !isLoading && pathIsPrivate) replace(loginRoute)
8182
if (isAuth && !isLoading && pathIsPublic) replace(access)
8283
if (isAuth && userRole && !isLoading && !pathIsHybrid && !pathIsAuthorized)
@@ -99,8 +100,10 @@ export function NextShield<
99100
((isLoading || isAuth) && pathIsPublic) ||
100101
((isLoading || userRole) && !pathIsAuthorized) ||
101102
(isLoading && pathIsHybrid)
102-
)
103+
) {
104+
console.log('hey')
103105
return <>{LoadingComponent}</>
106+
}
104107

105108
return <>{children}</>
106109
}

0 commit comments

Comments
 (0)