Skip to content

Commit

Permalink
fix(rbac): replace added for redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
imjulianeral committed Sep 2, 2021
1 parent d44e4c4 commit c957a4f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
13 changes: 9 additions & 4 deletions example/ts-fire-example/components/router/Shield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ export function Shield({ children }: Props) {
LoadingComponent: <Loading />,
privateRoutes: ['/profile', '/dashboard', '/control-panel'],
publicRoutes: ['/', '/login'],
accessRoute: '/profile',
loginRoute: '/login',
RBAC: {
ADMIN: ['/profile', '/control-panel'],
USER: ['/profile', '/dashboard'],
ADMIN: {
grantedRoutes: ['/profile', '/control-panel'],
accessRoute: '/profile',
},
USER: {
grantedRoutes: ['/profile', '/dashboard'],
accessRoute: '/dashboard',
},
},
userRole: value?.role,
userRole: value?.role as string,
}

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": "^1.0.1",
"next-shield": "^2.0.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-firebase-hooks": "^3.0.4",
Expand Down
4 changes: 2 additions & 2 deletions src/components/NextShield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export function NextShield<
useEffect(() => {
if (!isAuth && !isLoading && pathIsPrivate) replace(loginRoute)
if (isAuth && !isLoading && pathIsPublic)
getAccessRoute(RBAC, userRole, accessRoute, loginRoute)
replace(getAccessRoute(RBAC, userRole, accessRoute, loginRoute))

if (isAuth && userRole && !isLoading && !pathIsHybrid && !pathIsAuthorized)
getAccessRoute(RBAC, userRole, accessRoute, loginRoute)
replace(getAccessRoute(RBAC, userRole, accessRoute, loginRoute))
}, [
replace,
userRole,
Expand Down

0 comments on commit c957a4f

Please sign in to comment.