Skip to content

Commit c599f65

Browse files
committed
modify hooks to allow regex use for specifying public routes
1 parent e052008 commit c599f65

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/hooks.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { TOKEN_NAME, parseTokenToJwt } from 'services/auth/token'
44
import type { UserAuthCredentials } from 'services/user/user'
55
import { getUserAuthCredentials } from 'services/user/user-auth-service'
66

7-
const PUBLIC_ROUTES = ['/', '/login', '/signup']
7+
const PUBLIC_ROUTES = [/^\/$/, /^\/login$/, /^\/signup$/, /^\/api\/*/]
88

99
export const handle: Handle = async ({ event, resolve }) => {
1010
const { locals, cookies, url } = event
@@ -25,7 +25,7 @@ export const handle: Handle = async ({ event, resolve }) => {
2525
locals.user = undefined
2626
}
2727

28-
if (PUBLIC_ROUTES.includes(pathname) || userAuthCredentials) {
28+
if (userAuthCredentials || PUBLIC_ROUTES.some((it) => it.test(pathname))) {
2929
return await resolve(event)
3030
}
3131

0 commit comments

Comments
 (0)