Skip to content

Commit

Permalink
Merge pull request #187 from denoland/refactor-cleanup-createSupabase…
Browse files Browse the repository at this point in the history
…Client()

refactor: minor cleanup of `createServerSupabaseClient()`
  • Loading branch information
iuioiua authored May 14, 2023
2 parents 6d18bda + 643349e commit 88256ad
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,24 @@ export type SupabaseClient = ReturnType<typeof createSupabaseClient>;

export function createSupabaseClient(
requestHeaders: Headers,
responseHeaders?: Headers,
responseHeaders: Headers,
) {
return createServerSupabaseClient({
supabaseUrl: Deno.env.get("SUPABASE_API_URL")!,
supabaseKey: Deno.env.get("SUPABASE_ANON_KEY")!,
getRequestHeader: (key) => requestHeaders.get(key) ?? undefined,
getCookie: (name) => {
const cookie = getCookies(requestHeaders)[name] ?? "";
return decodeURIComponent(cookie);
},
setCookie: (name, value, options) => {
if (responseHeaders) {
setCookie(responseHeaders, {
name,
value: encodeURIComponent(value),
...options,
sameSite: "Lax",
httpOnly: false,
});
}
const cookie = getCookies(requestHeaders)[name];
return cookie ? decodeURIComponent(cookie) : undefined;
},
setCookie: (name, value, options) =>
setCookie(responseHeaders, {
name,
value: encodeURIComponent(value),
...options,
sameSite: "Lax",
httpOnly: false,
}),
});
}

Expand Down

0 comments on commit 88256ad

Please sign in to comment.