Skip to content

Commit

Permalink
fix(rbac): check
Browse files Browse the repository at this point in the history
  • Loading branch information
imjulianeral committed Sep 2, 2021
1 parent 19f16ec commit 46dab1d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion example/ts-fire-example/components/router/Shield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function Shield({ children }: Props) {
accessRoute: '/dashboard',
},
},
userRole: value?.role as string,
userRole: value?.role ?? 'USER',
}

if (error) return <p>{error}</p>
Expand Down
6 changes: 3 additions & 3 deletions example/ts-fire-example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/ts-fire-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 12 additions & 14 deletions src/components/NextShield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 46dab1d

Please sign in to comment.