Skip to content

Commit 1ef50c9

Browse files
authored
ENG-989: Prune and describe client options (#508)
1 parent 5d03e35 commit 1ef50c9

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

apps/website/app/utils/supabase/client.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

apps/website/app/utils/supabase/middleware.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { createServerClient } from "@supabase/ssr";
22
import { NextResponse, type NextRequest } from "next/server";
33
import { envContents } from "@repo/database/dbDotEnv";
44

5+
// This would allow to create Next pages gated by a login middleware,
6+
// as described here: https://nextjs.org/docs/app/api-reference/file-conventions/middleware
7+
// Not usable yet, waiting for ENG-373
58
// Inspired by https://supabase.com/ui/docs/nextjs/password-based-auth
69

710
export const updateSession = async (request: NextRequest) => {
@@ -17,10 +20,8 @@ export const updateSession = async (request: NextRequest) => {
1720

1821
const supabase = createServerClient(supabaseUrl, supabaseKey, {
1922
cookies: {
20-
getAll() {
21-
return request.cookies.getAll();
22-
},
23-
setAll(cookiesToSet) {
23+
getAll: () => request.cookies.getAll(),
24+
setAll: (cookiesToSet) => {
2425
cookiesToSet.forEach(({ name, value }) =>
2526
request.cookies.set(name, value),
2627
);

apps/website/app/utils/supabase/server.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { cookies } from "next/headers";
33
import type { Database } from "@repo/database/dbTypes";
44
import { envContents } from "@repo/database/dbDotEnv";
55

6+
// This is a supabase client to be used in a server process such as NextJS
67
// Inspired by https://supabase.com/ui/docs/nextjs/password-based-auth
78

89
export const createClient = async () => {
@@ -18,16 +19,16 @@ export const createClient = async () => {
1819
// following https://supabase.com/docs/guides/auth/server-side/creating-a-client?queryGroups=environment&environment=server
1920
return createServerClient<Database>(supabaseUrl, supabaseKey, {
2021
cookies: {
21-
getAll() {
22+
getAll: () => {
2223
return cookieStore.getAll();
2324
},
24-
setAll(
25+
setAll: (
2526
cookiesToSet: {
2627
name: string;
2728
value: string;
2829
options: CookieOptions;
2930
}[],
30-
) {
31+
) => {
3132
try {
3233
cookiesToSet.forEach(
3334
({

packages/database/supabase/functions/create-space/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ Deno.serve(async (req) => {
220220
headers: { "Content-Type": "application/json" },
221221
});
222222
}
223+
// note: If we wanted this to be bound by permissions, we'd set the following options:
224+
// { global: { headers: { Authorization: req.headers.get('Authorization')! } } }
225+
// But the point here is to bypass RLS
223226
const supabase: DGSupabaseClient = createClient(url, key);
224227

225228
const { data, error } = await processAndGetOrCreateSpace(supabase, input);

0 commit comments

Comments
 (0)