From 81b0e3bf3fa5fd8c67e933bc88ead2087f3a1d3b Mon Sep 17 00:00:00 2001 From: spencerwooo Date: Thu, 2 Sep 2021 21:53:31 +0100 Subject: [PATCH] fix protected route could be empty --- utils/tools.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/utils/tools.ts b/utils/tools.ts index 3a4983e..7a9cd7f 100644 --- a/utils/tools.ts +++ b/utils/tools.ts @@ -44,19 +44,23 @@ export const useStaleSWR = (url: Key, path: string = '') => { } export const matchProtectedRoute = (route: string) => { - const protectedRoutes = siteConfig.protectedRoutes + const protectedRoutes: string[] = siteConfig.protectedRoutes let authTokenPath = '' + for (const r of protectedRoutes) { - if ( - route.startsWith( - r - .split('/') - .map(p => encodeURIComponent(p)) - .join('/') - ) - ) { - authTokenPath = r - break + // protected route array could be empty + if (r) { + if ( + route.startsWith( + r + .split('/') + .map(p => encodeURIComponent(p)) + .join('/') + ) + ) { + authTokenPath = r + break + } } } return authTokenPath