-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.ts
39 lines (31 loc) · 984 Bytes
/
middleware.ts
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
36
37
38
39
import { withAuth } from "next-auth/middleware";
import { NextResponse } from 'next/server';
export default withAuth(
// `withAuth` augments your `Request` with the user's token.
function middleware(request: NextResponse) {
return NextResponse.rewrite(new URL( request.url ));
},
{
callbacks: {
authorized: async({ token }) => {
if ( token?.accessToken ) {
const req = await fetch(
process.env.NEXT_PUBLIC_JWT_BASE + 'token/validate',
{
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization" : "Bearer " + token.accessToken,
}
}
);
const login_token = await req.json();
if ( login_token.code === 'jwt_auth_valid_token' ) {
return true;
}
}
}
}
}
)
export const config = { matcher: ["/", "/blogs"] }