-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
31 lines (25 loc) · 873 Bytes
/
proxy.ts
File metadata and controls
31 lines (25 loc) · 873 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
import { NextRequest, NextResponse } from 'next/server';
const REQUIRED_AUTH_COOKIES = ['auth_account_id', 'auth_session_id', 'auth_session_key'] as const;
function hasAuthCookies(request: NextRequest) {
return REQUIRED_AUTH_COOKIES.every((name) => {
const value = request.cookies.get(name)?.value;
return Boolean(value && value.trim());
});
}
export default function proxy(request: NextRequest) {
if (hasAuthCookies(request)) {
return NextResponse.next();
}
if (process.env.NODE_ENV === 'development') {
return NextResponse.next();
}
return NextResponse.redirect(
new URL(
'https://neupgroup.com/account/auth/start?appid=neupcode&redirectsTo=' +
encodeURIComponent(request.nextUrl.href),
),
);
}
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico|robots.txt|sitemap.xml).*)'],
};