From 668074224d3509b6f989a28a968dff5037865457 Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 13 Jul 2020 13:59:02 +0700 Subject: [PATCH] chore: #1997 redirect to 404 if not admin --- .../admin-portal/src/core/__tests__/private-route.tsx | 10 ++++++++++ packages/admin-portal/src/core/private-route.tsx | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/admin-portal/src/core/__tests__/private-route.tsx b/packages/admin-portal/src/core/__tests__/private-route.tsx index 3e9ba0d44d..a414f71c53 100644 --- a/packages/admin-portal/src/core/__tests__/private-route.tsx +++ b/packages/admin-portal/src/core/__tests__/private-route.tsx @@ -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) + }) }) }) diff --git a/packages/admin-portal/src/core/private-route.tsx b/packages/admin-portal/src/core/private-route.tsx index 9aca413133..d6d428b745 100644 --- a/packages/admin-portal/src/core/private-route.tsx +++ b/packages/admin-portal/src/core/private-route.tsx @@ -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) + } } }