mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
fix: sms hook validation (#45208)
## TL;DR fixes a regression where sms provider creds blocked saving phone provider settings while the send sms hook was enabled ## Before https://github.com/user-attachments/assets/3d053f4a-4b14-4a91-a5c6-dcaa0c09d148 ## After https://github.com/user-attachments/assets/f24a8534-bf86-4389-8a26-564fb9886bda ## ref: - closes https://github.com/supabase/supabase/issues/45198 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Optimized internal validation logic for SMS provider configurations to improve code maintainability and structure. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
1 parent
f235fe87f7
commit
697b373b06
1 file changed
+7
-13
@@ -261,18 +261,15 @@ const smsProviderDisabledSchema = z
|
||||
// as the SMS hook will be used in place of the configured SMS provider
|
||||
const makeProviderOptionalWhenSMSHookEnabled = (
|
||||
config: ProjectAuthConfigData,
|
||||
schema: z.ZodObject<z.ZodRawShape>
|
||||
getSchema: (optional?: boolean) => z.ZodObject<z.ZodRawShape>
|
||||
) => {
|
||||
return config.HOOK_SEND_SMS_ENABLED ? schema.partial() : schema
|
||||
return config.HOOK_SEND_SMS_ENABLED ? getSchema(true).partial() : getSchema()
|
||||
}
|
||||
|
||||
// getPhoneProviderValidationSchema generate the validation schema for the SMS providers
|
||||
// based on whether the SMS hook is enabled
|
||||
export const getPhoneProviderValidationSchema = (config: ProjectAuthConfigData) => {
|
||||
const twilioSchema = makeProviderOptionalWhenSMSHookEnabled(
|
||||
config,
|
||||
getTwilioPhoneProviderSchema()
|
||||
)
|
||||
const twilioSchema = makeProviderOptionalWhenSMSHookEnabled(config, getTwilioPhoneProviderSchema)
|
||||
.merge(
|
||||
z.object({
|
||||
SMS_PROVIDER: z.literal('twilio'),
|
||||
@@ -287,7 +284,7 @@ export const getPhoneProviderValidationSchema = (config: ProjectAuthConfigData)
|
||||
|
||||
const twilioVerifySchema = makeProviderOptionalWhenSMSHookEnabled(
|
||||
config,
|
||||
getTwilioVerifyPhoneProviderSchema()
|
||||
getTwilioVerifyPhoneProviderSchema
|
||||
)
|
||||
.merge(
|
||||
z.object({
|
||||
@@ -302,7 +299,7 @@ export const getPhoneProviderValidationSchema = (config: ProjectAuthConfigData)
|
||||
|
||||
const messagebirdSchema = makeProviderOptionalWhenSMSHookEnabled(
|
||||
config,
|
||||
getMessagebirdPhoneProviderSchema()
|
||||
getMessagebirdPhoneProviderSchema
|
||||
)
|
||||
.merge(
|
||||
z.object({
|
||||
@@ -316,10 +313,7 @@ export const getPhoneProviderValidationSchema = (config: ProjectAuthConfigData)
|
||||
.merge(getVonagePhoneProviderSchema(true).partial())
|
||||
.merge(getTextlocalPhoneProviderSchema(true).partial())
|
||||
|
||||
const vonageSchema = makeProviderOptionalWhenSMSHookEnabled(
|
||||
config,
|
||||
getVonagePhoneProviderSchema()
|
||||
)
|
||||
const vonageSchema = makeProviderOptionalWhenSMSHookEnabled(config, getVonagePhoneProviderSchema)
|
||||
.merge(
|
||||
z.object({
|
||||
SMS_PROVIDER: z.literal('vonage'),
|
||||
@@ -334,7 +328,7 @@ export const getPhoneProviderValidationSchema = (config: ProjectAuthConfigData)
|
||||
|
||||
const textlocalSchema = makeProviderOptionalWhenSMSHookEnabled(
|
||||
config,
|
||||
getTextlocalPhoneProviderSchema()
|
||||
getTextlocalPhoneProviderSchema
|
||||
)
|
||||
.merge(
|
||||
z.object({
|
||||
|
||||
Reference in new issue
Block a user