fix(middleware): exempt manifest.json and sw.js from the auth matcher
Logged-out requests were redirected to /login, and logged-in non-admin roles were bounced to their home page, which blocked PWA install and the service worker. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -47,5 +47,5 @@ export async function middleware(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
matcher: ['/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)'],
|
matcher: ['/((?!_next/static|_next/image|favicon.ico|manifest\\.json$|sw\\.js$|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)'],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import { config } from '@/middleware'
|
||||||
|
|
||||||
|
const re = new RegExp(`^${config.matcher[0]}$`)
|
||||||
|
|
||||||
|
describe('middleware matcher', () => {
|
||||||
|
it.each(['/manifest.json', '/sw.js', '/_next/static/chunks/a.js', '/favicon.ico', '/icons/icon-192.png'])(
|
||||||
|
'skips public asset %s so PWA files load without a session',
|
||||||
|
path => {
|
||||||
|
expect(re.test(path)).toBe(false)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
it.each(['/', '/login', '/hse/incidents', '/api/incidents', '/manifest.jsonx', '/app/sw.js'])(
|
||||||
|
'still guards %s',
|
||||||
|
path => {
|
||||||
|
expect(re.test(path)).toBe(true)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user