forked from enricoros/big-AGI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
45 lines (34 loc) · 1.12 KB
/
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
40
41
42
43
44
45
/**
* Middleware to protect `big-AGI` with a password prompt
*
* For more information on how to deploy with password protection, see:
* - [deploy-authentication.md](docs/deploy-authentication.md)
*/
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';
// noinspection JSUnusedGlobalSymbols
export function middleware(request: NextRequest) {
// Validate deployment configuration
if (!process.env.PAGE_PASSWORD) {
console.warn('Page password is not configured');
return new Response('Unconfigured', { status: 401 });
}
const storedPassword = request.cookies.get('page-password')?.value;
if (!storedPassword) {
return NextResponse.redirect(new URL('/login', request.url,));
}
if (storedPassword !== process.env.PAGE_PASSWORD) {
return NextResponse.redirect(new URL('/login?wrong=true', request.url));
}
return NextResponse.next();
}
export const config = {
matcher: [
// Include root
'/',
// Include pages
'/(call|index|news|personas|link)(.*)',
// Include API routes
// Note: this excludes _next, /images etc..
],
};