-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
36 lines (30 loc) · 926 Bytes
/
proxy.ts
File metadata and controls
36 lines (30 loc) · 926 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
32
33
34
35
36
import { NextResponse, type NextRequest } from 'next/server';
import { createServerSupabase } from './lib/supabase/server';
export async function proxy(req: NextRequest) {
const url = req.nextUrl.clone();
const supabase = await createServerSupabase();
const {
data: { session },
} = await supabase.auth.getSession();
const { pathname } = url;
if (!session && (pathname.startsWith('/explore') || pathname.startsWith('/images') || pathname.startsWith('/top') || pathname.startsWith('/likes'))) {
url.pathname = '/login';
return NextResponse.redirect(url);
}
if (session && (pathname === '/login' || pathname === '/signup')) {
url.pathname = '/explore';
return NextResponse.redirect(url);
}
return NextResponse.next();
}
export const config = {
matcher: [
'/explore',
'/images',
'/top',
'/likes',
'/api/generations/:path*',
'/login',
'/signup',
],
};