Refactor Supabase client and service role key usage
The refactoring includes the moving of the `getSupabaseClientKeys()` and `getServiceRoleKey()` function calls to the module scope and the addition of a `warnServiceRoleKeyUsage()` function, used to display a warning when the Supabase Service Role is accessed. The change aims to improve code readability and maintainability.
This commit is contained in:
@@ -5,12 +5,16 @@ import { cookies } from 'next/headers';
|
||||
import { createServerClient } from '@supabase/ssr';
|
||||
|
||||
import { Database } from '../database.types';
|
||||
import { getServiceRoleKey } from '../get-service-role-key';
|
||||
import {
|
||||
getServiceRoleKey,
|
||||
warnServiceRoleKeyUsage,
|
||||
} from '../get-service-role-key';
|
||||
import { getSupabaseClientKeys } from '../get-supabase-client-keys';
|
||||
|
||||
function createServerSupabaseClient() {
|
||||
const keys = getSupabaseClientKeys();
|
||||
const keys = getSupabaseClientKeys();
|
||||
const serviceRoleKey = getServiceRoleKey();
|
||||
|
||||
function createServerSupabaseClient() {
|
||||
return createServerClient<Database>(keys.url, keys.anonKey, {
|
||||
cookies: getCookiesStrategy(),
|
||||
});
|
||||
@@ -23,7 +27,7 @@ export function getSupabaseServerActionClient<
|
||||
const admin = params?.admin ?? false;
|
||||
|
||||
if (admin) {
|
||||
const serviceRoleKey = getServiceRoleKey();
|
||||
warnServiceRoleKeyUsage();
|
||||
|
||||
return createServerClient<GenericSchema>(keys.url, serviceRoleKey, {
|
||||
auth: {
|
||||
|
||||
Reference in New Issue
Block a user