redirect unauthenticated users to the home page

This commit is contained in:
EGOIST 2022-05-12 01:25:09 +08:00
parent 5355a9d9a6
commit 744a47f416
1 changed files with 12 additions and 0 deletions

View File

@ -0,0 +1,12 @@
import { NextRequest, NextResponse } from "next/server"
import { AUTH_COOKIE_NAME } from "~/lib/env.server"
export default function middleware(req: NextRequest) {
// Redirect unauthenticated users to the home page
if (!req.cookies[AUTH_COOKIE_NAME]) {
const url = req.nextUrl.clone()
url.pathname = "/"
return NextResponse.redirect(url)
}
return NextResponse.next()
}