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:
@@ -1,20 +1,16 @@
|
||||
import { invariant } from '@epic-web/invariant';
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* Returns and validates the Supabase client keys from the environment.
|
||||
*/
|
||||
export function getSupabaseClientKeys() {
|
||||
const env = process.env;
|
||||
|
||||
invariant(env.NEXT_PUBLIC_SUPABASE_URL, `Supabase URL not provided`);
|
||||
|
||||
invariant(
|
||||
env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
|
||||
`Supabase Anon Key not provided`,
|
||||
);
|
||||
|
||||
return {
|
||||
url: env.NEXT_PUBLIC_SUPABASE_URL,
|
||||
anonKey: env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
|
||||
};
|
||||
return z
|
||||
.object({
|
||||
url: z.string().min(1),
|
||||
anonKey: z.string().min(1),
|
||||
})
|
||||
.parse({
|
||||
url: process.env.NEXT_PUBLIC_SUPABASE_URL,
|
||||
anonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user