middleware
Unanswered
astro posted this in #help-forum
astroOP
import { auth } from "@/server/auth";
const publicPages = ["/", "/login"];
export default auth((req) => {
if (!req.auth && !publicPages.includes(req.nextUrl.pathname)) {
const newUrl = new URL("/api/auth/signin", req.nextUrl.origin);
return Response.redirect(newUrl);
}
});
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};this is running checks on assets too it seems
4 Replies
@astro ts
import { auth } from "@/server/auth";
const publicPages = ["/", "/login"];
export default auth((req) => {
if (!req.auth && !publicPages.includes(req.nextUrl.pathname)) {
const newUrl = new URL("/api/auth/signin", req.nextUrl.origin);
return Response.redirect(newUrl);
}
});
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};
this is running checks on assets too it seems
Yeah I think you are facing the same problem as this person https://nextjs-forum.com/post/1251204481090064405
For the image, instead of using the url path, statically import the image instead (and you don't need to put the image inside
https://nextjs.org/docs/app/building-your-application/optimizing/images#local-images
public in that case)https://nextjs.org/docs/app/building-your-application/optimizing/images#local-images
@joulev For the image, instead of using the url path, statically import the image instead (and you don't need to put the image inside `public` in that case)
<https://nextjs.org/docs/app/building-your-application/optimizing/images#local-images>
astroOP
well i’d rather prefer keeping it in public dir so is there any workaround with that approach
@astro well i’d rather prefer keeping it in public dir so is there any workaround with that approach
Then you have to edit the matcher regex, or the middleware logic, to detect static files and handle them accordingly. Both are not easy. Regex is never easy.