-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.js
More file actions
32 lines (28 loc) · 798 Bytes
/
middleware.js
File metadata and controls
32 lines (28 loc) · 798 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 { NextResponse } from "next/server";
import { verify } from "./utils/server-utils";
export async function middleware(req) {
// const { pathname } = req.nextUrl;
try {
const token = req.headers.get("auth-token");
const { userId } = await verify(token, process.env.JWT_PRIVATE_KEY);
// console.log(userId.id);
const response = NextResponse.next();
response.headers.set("user-id", userId.id);
return response;
} catch (error) {
return NextResponse.json(
{ message: "Please authenticate using valid token" },
{ status: 401 }
);
}
}
// "Matching Paths"
export const config = {
matcher: [
"/api/solutions/getall",
"/api/solutions/add",
"/api/solutions/update",
"/api/solutions/remove",
"/api/solutions/search",
],
};