Add error message for invalid Supabase Service Role Key

The code now supplies a detailed error message when an invalid Supabase Service Role Key is provided. The error message prompts the user to check the SUPABASE_SERVICE_ROLE_KEY environment variable ensuring clearer debugging.
This commit is contained in:
giancarlo
2024-04-14 18:27:39 +08:00
parent 7dcd688ca9
commit 81f1bbca3b

View File

@@ -2,6 +2,9 @@ import 'server-only';
import { z } from 'zod';
const message =
'Invalid Supabase Service Role Key. Please check the environment variable SUPABASE_SERVICE_ROLE_KEY.';
/**
* @name getServiceRoleKey
* @description Get the Supabase Service Role Key.
@@ -9,7 +12,15 @@ import { z } from 'zod';
*/
export function getServiceRoleKey() {
const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
return z.string().min(1).parse(serviceRoleKey);
return z
.string({
required_error: message,
})
.min(1, {
message: message,
})
.parse(serviceRoleKey);
}
/**