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:
@@ -1,3 +1,5 @@
|
||||
import 'server-only';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
@@ -7,12 +9,16 @@ import { z } from 'zod';
|
||||
*/
|
||||
export function getServiceRoleKey() {
|
||||
const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
|
||||
return z.string().min(1).parse(serviceRoleKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a warning message if the Supabase Service Role is being used.
|
||||
*/
|
||||
export function warnServiceRoleKeyUsage() {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.warn(
|
||||
`[Dev Only] This is a simple warning to let you know you are using the Supabase Service Role. Make sure it's the right call.`,
|
||||
);
|
||||
}
|
||||
|
||||
return z.string().min(1).parse(serviceRoleKey);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user