-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
33 lines (28 loc) · 1.03 KB
/
Copy pathproxy.ts
File metadata and controls
33 lines (28 loc) · 1.03 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
import { createServerClient } from "@supabase/ssr";
import { NextResponse, type NextRequest } from "next/server";
/**
* Refreshes the organiser's Supabase session cookie on admin routes. Server
* Components cannot write cookies, so without this a session would silently
* expire mid-review.
*/
export default async function proxy(request: NextRequest) {
let response = NextResponse.next({ request });
const url = process.env.NEXT_PUBLIC_SUPABASE_URL;
const key = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
if (!url || !key) return response;
const supabase = createServerClient(url, key, {
cookies: {
getAll: () => request.cookies.getAll(),
setAll: (toSet) => {
for (const { name, value } of toSet) request.cookies.set(name, value);
response = NextResponse.next({ request });
for (const { name, value, options } of toSet) response.cookies.set(name, value, options);
},
},
});
await supabase.auth.getUser();
return response;
}
export const config = {
matcher: ["/admin/:path*"],
};