-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
37 lines (30 loc) · 1.21 KB
/
proxy.ts
File metadata and controls
37 lines (30 loc) · 1.21 KB
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
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();
}
// Remove this line of code only during the development.
// =================>
if (process.env.NODE_ENV === 'development') {
return NextResponse.next();
}
// =================>
// Enable these lines of code only during the development.
const appid = Math.random().toString(36).substring(2, 10);
const redirectUrl = new URL('https://neupgroup.com/account/auth/start');
redirectUrl.searchParams.set('appid', process.env.APP_ID || appid);
redirectUrl.searchParams.set('redirectsTo', request.nextUrl.href);
return NextResponse.redirect(redirectUrl);
}
export const config = {
matcher: [
'/((?!_next(?:/.*)?|bridge(?:/.*)?|robots\\.txt$|sitemap\\.xml$|sitemap(?:/.*)?|favicon\\.ico$|humans\\.txt$|\\.well-known(?:/.*)?).*)',
],
};