werz0xff
werz0xff
TTCTheo's Typesafe Cult
Created by werz0xff on 9/20/2023 in #questions
Vercel responding with 405 for a api route
the api path is correct, i think vercel thinks of it as a static route
23 replies
TTCTheo's Typesafe Cult
Created by werz0xff on 9/11/2023 in #questions
Nextjs middleware being ignored
Hey, this is driving me crazy, using next, why I'm not being redirected to "/pending" by the middleware when pushed to "/dashboard" from a different (login) route using useRouter push login.tsx route
function goToDashboard(){
router.push('/dashboard');
}
return <button onClick={goToDashboard}>go</button>
function goToDashboard(){
router.push('/dashboard');
}
return <button onClick={goToDashboard}>go</button>
root middlware middleware.ts
export async function middleware(req: NextRequest) {
const res = NextResponse.next();
const { pathname } = req.nextUrl
const status = "pending"
const user = true
if (pathname.startsWith("/dashboard")) {
if (!user) {
return redirect("/login", req);
}
if (status === "pending") {
return redirect("/pending", req);
}
}
return res
}

export const config = {
matcher: [
"/dashboard",
"/login",
"/pending",
],
};
export async function middleware(req: NextRequest) {
const res = NextResponse.next();
const { pathname } = req.nextUrl
const status = "pending"
const user = true
if (pathname.startsWith("/dashboard")) {
if (!user) {
return redirect("/login", req);
}
if (status === "pending") {
return redirect("/pending", req);
}
}
return res
}

export const config = {
matcher: [
"/dashboard",
"/login",
"/pending",
],
};
6 replies