danmu-sim/middleware.ts

20 lines
608 B
TypeScript
Raw Normal View History

2024-04-05 15:35:01 +08:00
import type { NextRequest } from 'next/server'
export function middleware(request: NextRequest) {
const currentUser = request.cookies.get('token')?.value
if (currentUser && !request.nextUrl.pathname.startsWith('/')) {
return Response.redirect(new URL('/', request.url))
}
if (!currentUser
&& !request.nextUrl.pathname.startsWith('/signin')
&& !request.nextUrl.pathname.startsWith('/signup')
) {
return Response.redirect(new URL('/signin', request.url))
}
}
export const config = {
matcher: ['/((?!api|_next/static|_next/image|.*\\.png$).*)'],
}