I have already made a couple of pwa projects with Next JS but this time my site.webmanifest file does not load. When I look at the site.webmanifest in the browser I see it loads an html file with the starting page.
site.webmanifest:
{
"name": "Task Manager",
"short_name": "Task Manager",
"description": "Application to save tasks",
"display": "standalone",
"start_url": "/",
"icons": [
{
"src": "/icons/manifest-icon-192.maskable.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
},
{
"src": "/icons/manifest-icon-192.maskable.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "/icons/manifest-icon-512.maskable.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any"
},
{
"src": "/icons/manifest-icon-512.maskable.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
]
}
_middleware.tsx:
import { NextFetchEvent, NextRequest, NextResponse } from "next/server";
export function middleware(req: NextRequest, event: NextFetchEvent) {
const jwt = req.cookies["jwt"];
const urlArray: Array<string> = req.url.split("/");
const baseUrl = `${urlArray[0]}//${urlArray[2]}`;
if (req.url !== `${baseUrl}/login` && !jwt) {
return NextResponse.redirect(`${baseUrl}/login`);
}
}
link to manifest in _document.tsx
<link rel="manifest" href="/site.webmanifest" />
Error: Error on browser console
EDIT: I found out that this error happens because I use middleware to redirect to the login page when unauthenticated. But I still don't have a solution for this problem because I want to keep the middleware.