Skip to content

Commit

Permalink
chore: #1997 redirect to 404 if not admin
Browse files Browse the repository at this point in the history
  • Loading branch information
undefined committed Jul 13, 2020
1 parent cd66789 commit 6680742
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/admin-portal/src/core/__tests__/private-route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,15 @@ describe('PrivateRouter', () => {
fn()
expect(history.replace).toBeCalledWith(`${Routes.AUTHENTICATION}/${mockAllow.toLowerCase()}`)
})

it('should redirect to 404 page if land on admin page, and is not admin', () => {
const mockLoginIdentity = {
clientId: 'testClientId',
} as LoginIdentity
const mockAllow = 'ADMIN'
const fn = handleRedirectToAuthenticationPage(mockAllow, history, mockLoginIdentity)
fn()
expect(history.replace).toBeCalledWith(Routes.FOUR_O_FOUR)
})
})
})
6 changes: 5 additions & 1 deletion packages/admin-portal/src/core/private-route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ export const handleRedirectToAuthenticationPage = (
if (!loginIdentity || isFetchingAccessToken) {
return
}
const { clientId, developerId } = loginIdentity
const { clientId, developerId, adminId } = loginIdentity
if ((allow === 'CLIENT' && !clientId) || (allow === 'DEVELOPER' && !developerId)) {
history.replace(`${Routes.AUTHENTICATION}/${allow.toLowerCase()}`)
}

if (allow === 'ADMIN' && !adminId) {
history.replace(Routes.FOUR_O_FOUR)
}
}
}

Expand Down

0 comments on commit 6680742

Please sign in to comment.