forked from mrwyndham/fastpocket
24 lines
624 B
JavaScript
24 lines
624 B
JavaScript
import { NextResponse } from "next/server"
|
|
import { isAuthenticated } from "./lib/auth"
|
|
|
|
export async function middleware(request) {
|
|
const { pathname } = request.nextUrl
|
|
if (
|
|
pathname.startsWith("/_next") ||
|
|
pathname.startsWith("/api") ||
|
|
pathname.startsWith("/static")
|
|
) {
|
|
return NextResponse.next()
|
|
}
|
|
const isLoggedIn = await isAuthenticated(request.cookies)
|
|
if (pathname.startsWith("/account")) {
|
|
if (isLoggedIn) {
|
|
return NextResponse.next()
|
|
} else {
|
|
request.nextUrl.pathname = "/"
|
|
}
|
|
return NextResponse.redirect(request.nextUrl)
|
|
}
|
|
return NextResponse.next()
|
|
}
|