-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
28 lines (24 loc) · 1004 Bytes
/
middleware.ts
File metadata and controls
28 lines (24 loc) · 1004 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
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import AppConfig from './models/AppConfig';
export function middleware(request: NextRequest) {
if (!request.cookies.get('vtcm_session'))
return NextResponse.redirect(new URL('/login', request.url));
let url = AppConfig.server_url + 'api/webapp/check';
fetch(url, { headers: new Headers({ 'Authorization': 'Bearer ' + atob(request.cookies.get('vtcm_session')), 'Accept': 'application/json' }) }).then((response) => {
if (response.ok) {
return response.json();
} else {
return NextResponse.redirect(new URL('/login', request.url));
}
}).then(authResult => {
if (!authResult["id"]) {
return NextResponse.redirect(new URL('/login', request.url));
}
}).catch(e => {
return NextResponse.redirect(new URL('/login', request.url));
});
}
export const config = {
matcher: ['/company/:path*', '/job/:path*', '/companies', '/dashboard', '/logbook', '/logout'],
}