-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathproxy.ts
More file actions
57 lines (49 loc) · 1.45 KB
/
Copy pathproxy.ts
File metadata and controls
57 lines (49 loc) · 1.45 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
import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
import { createServerClient } from "@supabase/ssr"
export async function proxy(req: NextRequest) {
const res = NextResponse.next()
const supabaseUrl = process.env.NEXT_PUBLIC_JIOBASE_URL || process.env.NEXT_PUBLIC_SUPABASE_URL
if (!supabaseUrl || !process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY) {
return res
}
const supabase = createServerClient(
supabaseUrl,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
{
cookies: {
get(name: string) {
return req.cookies.get(name)?.value
},
set(name, value, options) {
res.cookies.set({ name, value, ...options })
},
remove(name, options) {
res.cookies.set({ name, value: "", ...options })
},
},
}
)
const {
data: { user },
} = await supabase.auth.getUser()
const isProtected =
req.nextUrl.pathname.startsWith("/dashboard") ||
req.nextUrl.pathname.startsWith("/feedback") ||
req.nextUrl.pathname.startsWith("/checkpoints") ||
req.nextUrl.pathname.startsWith("/announcements") ||
req.nextUrl.pathname.startsWith("/profile")
if (!user && isProtected) {
return NextResponse.redirect(new URL("/login", req.url))
}
return res
}
export const config = {
matcher: [
"/dashboard/:path*",
"/feedback/:path*",
"/checkpoints/:path*",
"/announcements/:path*",
"/profile/:path*",
],
}