Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions apps/website/app/utils/supabase/client.ts

This file was deleted.

9 changes: 5 additions & 4 deletions apps/website/app/utils/supabase/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { createServerClient } from "@supabase/ssr";
import { NextResponse, type NextRequest } from "next/server";
import { envContents } from "@repo/database/dbDotEnv";

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

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

const supabase = createServerClient(supabaseUrl, supabaseKey, {
cookies: {
getAll() {
return request.cookies.getAll();
},
setAll(cookiesToSet) {
getAll: () => request.cookies.getAll(),
setAll: (cookiesToSet) => {
cookiesToSet.forEach(({ name, value }) =>
request.cookies.set(name, value),
);
Expand Down
7 changes: 4 additions & 3 deletions apps/website/app/utils/supabase/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { cookies } from "next/headers";
import type { Database } from "@repo/database/dbTypes";
import { envContents } from "@repo/database/dbDotEnv";

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

export const createClient = async () => {
Expand All @@ -18,16 +19,16 @@ export const createClient = async () => {
// following https://supabase.com/docs/guides/auth/server-side/creating-a-client?queryGroups=environment&environment=server
return createServerClient<Database>(supabaseUrl, supabaseKey, {
cookies: {
getAll() {
getAll: () => {
return cookieStore.getAll();
},
setAll(
setAll: (
cookiesToSet: {
name: string;
value: string;
options: CookieOptions;
}[],
) {
) => {
try {
cookiesToSet.forEach(
({
Expand Down
3 changes: 3 additions & 0 deletions packages/database/supabase/functions/create-space/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ Deno.serve(async (req) => {
headers: { "Content-Type": "application/json" },
});
}
// note: If we wanted this to be bound by permissions, we'd set the following options:
// { global: { headers: { Authorization: req.headers.get('Authorization')! } } }
// But the point here is to bypass RLS
const supabase: DGSupabaseClient = createClient(url, key);

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