-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
35 lines (28 loc) · 859 Bytes
/
middleware.ts
File metadata and controls
35 lines (28 loc) · 859 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
33
34
35
import withAuth from "next-auth/middleware";
import {NextResponse} from "next/server";
export default withAuth(
function middleware(req) {
return NextResponse.next()
},
{
callbacks: {
authorized: ({token , req}) => {
const {pathname} = req.nextUrl;
if(
pathname.startsWith("/api/auth") ||
pathname === "/login" ||
pathname === "/register"
) {
return true
}
if(pathname === "/" || pathname.startsWith("/api/videos")){
return !!token
}
return false
},
},
}
)
export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico|public/).*)"] ,
};