-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
161 lines (148 loc) · 5.69 KB
/
proxy.ts
File metadata and controls
161 lines (148 loc) · 5.69 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { signToken, verifyToken } from '@/lib/auth/session';
const protectedRoutes = '/dashboard';
const verificationRoute = '/verify-invitation';
const MAINTENANCE_HTML = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>She Sharp - We'll Be Back Soon</title>
<link rel="icon" href="/logos/she-sharp-logo-purple-dark-130x130.svg">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #f4f4fa;
padding: 1rem;
position: relative;
overflow: hidden;
}
.bg-circle {
position: absolute;
border-radius: 50%;
filter: blur(80px);
pointer-events: none;
}
.bg-circle-1 { top: 15%; right: -8rem; width: 16rem; height: 16rem; background: #f7e5f3; opacity: 0.6; }
.bg-circle-2 { bottom: 15%; left: -8rem; width: 16rem; height: 16rem; background: #eaf2ff; opacity: 0.6; }
.bg-circle-3 { top: 50%; left: 50%; transform: translate(-50%, -50%); width: 24rem; height: 24rem; background: #effefb; opacity: 0.4; }
.card {
position: relative;
z-index: 1;
background: white;
border: 1px solid #eaf2ff;
border-radius: 1rem;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
max-width: 28rem;
width: 100%;
padding: 3rem;
text-align: center;
}
.logo { width: 80px; height: 80px; margin: 0 auto 2rem; }
.title { font-size: 2rem; font-weight: 700; color: #1f1e44; margin-bottom: 1rem; }
.description { font-size: 1.05rem; line-height: 1.7; color: rgba(31, 30, 68, 0.7); margin-bottom: 2rem; }
.divider { border: none; border-top: 1px solid #eaf2ff; margin: 0 0 1.5rem; }
.footer { font-size: 0.875rem; color: rgba(31, 30, 68, 0.5); }
.brand { color: #9b2e83; }
</style>
</head>
<body>
<div class="bg-circle bg-circle-1"></div>
<div class="bg-circle bg-circle-2"></div>
<div class="bg-circle bg-circle-3"></div>
<div class="card">
<img src="/logos/she-sharp-logo-purple-dark-130x130.svg" alt="She Sharp" class="logo">
<h1 class="title">We'll Be Back Soon</h1>
<p class="description">
Our website is currently undergoing scheduled maintenance.
We're working to bring you a better experience and will be back online shortly.
</p>
<hr class="divider">
<p class="footer">© 2026 <span class="brand">She Sharp</span> — Connecting Women in Technology</p>
</div>
</body>
</html>`;
export async function proxy(request: NextRequest) {
// Maintenance mode: return 503 page when enabled via environment variable
if (process.env.MAINTENANCE_MODE === 'true') {
return new NextResponse(MAINTENANCE_HTML, {
status: 503,
headers: {
'Content-Type': 'text/html; charset=utf-8',
'Retry-After': '3600',
},
});
}
const { pathname } = request.nextUrl;
const sessionCookie = request.cookies.get('session');
const nextAuthSessionToken = request.cookies.get('authjs.session-token') ||
request.cookies.get('__Secure-authjs.session-token');
const oauthVerifiedCookie = request.cookies.get('oauth-verified');
const isProtectedRoute = pathname.startsWith(protectedRoutes);
const isVerificationRoute = pathname.startsWith(verificationRoute);
// Check for either custom session or NextAuth session
const hasCustomSession = !!sessionCookie;
const hasNextAuthSession = !!nextAuthSessionToken;
const hasValidSession = hasCustomSession || hasNextAuthSession;
// If no session at all, redirect to sign-in for protected routes
if (isProtectedRoute && !hasValidSession) {
return NextResponse.redirect(new URL('/sign-in', request.url));
}
// For OAuth users (NextAuth session only, no custom session),
// check if they need invitation verification
if (isProtectedRoute && hasNextAuthSession && !hasCustomSession) {
// Check for verification status cookie
if (!oauthVerifiedCookie) {
return NextResponse.redirect(new URL('/verify-invitation', request.url));
}
}
// Handle verification route access
if (isVerificationRoute) {
// Only allow if user has NextAuth session (OAuth user)
if (!hasNextAuthSession) {
return NextResponse.redirect(new URL('/sign-in', request.url));
}
// If user has custom session (credential login), redirect to dashboard
if (hasCustomSession) {
return NextResponse.redirect(new URL('/dashboard', request.url));
}
// If OAuth user already verified, redirect to dashboard
if (oauthVerifiedCookie) {
return NextResponse.redirect(new URL('/dashboard', request.url));
}
}
let res = NextResponse.next();
if (sessionCookie && request.method === 'GET') {
try {
const parsed = await verifyToken(sessionCookie.value);
const expiresInOneDay = new Date(Date.now() + 24 * 60 * 60 * 1000);
res.cookies.set({
name: 'session',
value: await signToken({
...parsed,
expires: expiresInOneDay.toISOString()
}),
httpOnly: true,
secure: true,
sameSite: 'lax',
expires: expiresInOneDay
});
} catch (error) {
console.error('Error updating session:', error);
res.cookies.delete('session');
if (isProtectedRoute) {
return NextResponse.redirect(new URL('/sign-in', request.url));
}
}
}
return res;
}
export const config = {
matcher: ['/((?!_next/static|_next/image|logos|favicon\\.ico).*)']
};