-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
32 lines (30 loc) · 883 Bytes
/
Copy pathmiddleware.ts
File metadata and controls
32 lines (30 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import withAuth from "next-auth/middleware";
import { NextResponse } from "next/server";
export default withAuth(
function middleware() {
return NextResponse.next();
},
{
callbacks: {
authorized: ({ token, req }: { token: any; req: any }) => {
const { pathname } = req.nextUrl;
if (
pathname.startsWith("/api/auth") ||
pathname === "/login" ||
pathname === "/register"
) {
return true;
}
if (pathname === "/" || pathname.startsWith("/api/videos")) {
return true;
}
return !!token;
},
},
}
);
export const config = {
matcher: [
"/((?!_next/static|_next/image|favicon.ico|public/).*)",
],
};