Skip to content

Commit

Permalink
fix(rbac): useEffect deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
imjulianeral committed Sep 2, 2021
1 parent 40583b6 commit f596a2a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 34 deletions.
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.10",
"next-shield": "^2.0.11",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-firebase-hooks": "^3.0.4",
Expand Down
46 changes: 17 additions & 29 deletions src/components/NextShield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,23 @@ export function NextShield<
RBAC && userRole && verifyPath(RBAC[userRole].grantedRoutes, pathname)
const access = getAccessRoute(RBAC, userRole, accessRoute) as string

console.log({
userRole,
access,
isAuth,
isLoading,
loginRoute,
pathIsPrivate,
pathIsPublic,
pathIsHybrid,
pathIsAuthorized,
})

useEffect(() => {
if (!isAuth && !isLoading && pathIsPrivate) replace(loginRoute)
if (isAuth && !isLoading && pathIsPublic) replace(access)
if (isAuth && userRole && !isLoading && !pathIsHybrid && !pathIsAuthorized)
replace(access)
}, [
replace,
userRole,
access,
isAuth,
isLoading,
loginRoute,
pathIsPrivate,
pathIsPublic,
pathIsHybrid,
pathIsAuthorized,
])
// useEffect(() => {
// if (!isAuth && !isLoading && pathIsPrivate) replace(loginRoute)
// if (isAuth && !isLoading && pathIsPublic) replace(access)
// if (isAuth && userRole && !isLoading && !pathIsHybrid && !pathIsAuthorized)
// replace(access)
// }, [
// replace,
// userRole,
// access,
// isAuth,
// isLoading,
// loginRoute,
// pathIsPrivate,
// pathIsPublic,
// pathIsHybrid,
// pathIsAuthorized,
// ])

if (
((isLoading || !isAuth) && pathIsPrivate) ||
Expand Down
2 changes: 1 addition & 1 deletion src/libs/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export function getAccessRoute(

if (RBAC && userRole) return RBAC[userRole].accessRoute

return undefined
return '/'
}

0 comments on commit f596a2a

Please sign in to comment.