Refactor key access and role warning in Supabase clients
The update simplifies accessing environment keys and role warnings in Supabase clients by moving them to new functions 'getSupabaseClientKeys' and 'getServiceRoleKey'. The redundancy in the code is reduced promoting clearer and more maintainable code. The '@epic-web/invariant' import has been removed from files as it is no longer needed.
This commit is contained in:
18
packages/supabase/src/get-service-role-key.ts
Normal file
18
packages/supabase/src/get-service-role-key.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* @name getServiceRoleKey
|
||||
* @description Get the Supabase Service Role Key.
|
||||
* ONLY USE IN SERVER-SIDE CODE. DO NOT EXPOSE THIS TO CLIENT-SIDE CODE.
|
||||
*/
|
||||
export function getServiceRoleKey() {
|
||||
const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.warn(
|
||||
`[Dev Only] 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