Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: add test otp

Stojan Dimitrovski645baca9bdca
diff --git a/studio/components/interfaces/Auth/AuthProvidersForm/FormField.tsx b/studio/components/interfaces/Auth/AuthProvidersForm/FormField.tsx
index a40dd0dbdf8..96f6a8dfb47 100644
--- a/studio/components/interfaces/Auth/AuthProvidersForm/FormField.tsx
+++ b/studio/components/interfaces/Auth/AuthProvidersForm/FormField.tsx
@@ -1,6 +1,8 @@
-import { useState } from 'react'
+import { useState, useEffect } from 'react'
import ReactMarkdown from 'react-markdown'
+import dayjs from 'dayjs'
import { Button, IconEye, IconEyeOff, Input, InputNumber, Listbox, Toggle } from 'ui'
+import { DatePicker } from 'components/ui/DatePicker'
import { BASE_PATH } from 'lib/constants'
import { Enum } from './AuthProvidersForm.types'
@@ -12,13 +14,81 @@ interface FormFieldProps {
disabled?: boolean
}
+function formatDate(date: Date): string {
+ return dayjs(date).format('dddd, MMMM D, YYYY HH:mm:ss Z')
+}
+
const FormField = ({ name, properties, formValues, disabled = false }: FormFieldProps) => {
const [hidden, setHidden] = useState(!!properties.isSecret)
+ const [dateAsText, setDateAsText] = useState(
+ formValues[name] ? formatDate(new Date(formValues[name])) : ''
+ )
- if (properties.show && !properties.show.matches.includes(formValues[properties.show.key]))
- return null
+ useEffect(() => {
+ if (properties.show && properties.show.key && !formValues[properties.show.key]) {
+ formValues[name] = ''
+ setDateAsText('')
+ }
+ }, [properties.show && properties.show.key && !formValues[properties.show.key]])
+
+ if (properties.show) {
+ if (properties.show.matches) {
+ if (!properties.show.matches.includes(formValues[properties.show.key])) {
+ return null
+ }
+ } else if (!formValues[properties.show.key]) {
+ return null
+ }
+ }
switch (properties.type) {
+ case 'datetime':
+ return (
+ <Input
+ size="small"
+ layout="vertical"
+ id={name}
+ name={name}
+ type="text"
+ value={dateAsText}
+ readOnly
+ label={properties.title}
+ labelOptional={
+ properties.descriptionOptional ? (
+ <ReactMarkdown unwrapDisallowed disallowedElements={['p']}>
+ {properties.descriptionOptional}
+ </ReactMarkdown>
+ ) : null
+ }
+ descriptionText={
+ properties.description ? (
+ <ReactMarkdown unwrapDisallowed disallowedElements={['p']}>
+ {properties.description}
+ </ReactMarkdown>
+ ) : null
+ }
+ actions={
+ <DatePicker
+ selectsRange={false}
+ minDate={new Date()}
+ from={formValues[name]}
+ to={formValues[name]}
+ onChange={(date) => {
+ if (date && date.to) {
+ formValues[name] = date.to
+ setDateAsText(formatDate(new Date(date.to)))
+ } else {
+ setDateAsText('')
+ formValues[name] = ''
+ }
+ }}
+ >
+ <span>Pick</span>
+ </DatePicker>
+ }
+ />
+ )
+
case 'string':
return (
<Input
diff --git a/studio/stores/authConfig/schema/AuthProviders/AuthProvidersFormValidation.tsx b/studio/stores/authConfig/schema/AuthProviders/AuthProvidersFormValidation.tsx
index ffb4a3eeab2..1df8fc716e7 100644
--- a/studio/stores/authConfig/schema/AuthProviders/AuthProvidersFormValidation.tsx
+++ b/studio/stores/authConfig/schema/AuthProviders/AuthProvidersFormValidation.tsx
@@ -1,4 +1,4 @@
-import { boolean, number, object, string, ValidationError } from 'yup'
+import { boolean, number, object, string, date, ValidationError } from 'yup'
import { urlRegex } from 'components/interfaces/Auth/Auth.constants'
const parseBase64URL = (b64url: string) => {
@@ -243,6 +243,21 @@ const PROVIDER_PHONE = {
matches: ['twilio', 'messagebird', 'textlocal', 'vonage'],
},
},
+ SMS_TEST_OTP: {
+ type: 'string',
+ title: 'Test Phone Numbers and OTPs',
+ description:
+ 'Register phone number and OTP combinations for testing as a comma separated list of <phone number>=<otp> pairs. Example: `18005550123=789012`',
+ },
+ SMS_TEST_OTP_VALID_UNTIL: {
+ type: 'datetime',
+ title: 'Test OTPs Valid Until',
+ description:
+ "Test phone number and OTP combinations won't be active past this date and time (local time zone).",
+ show: {
+ key: 'SMS_TEST_OTP',
+ },
+ },
},
validationSchema: object().shape({
EXTERNAL_PHONE_ENABLED: boolean().required(),
@@ -356,6 +371,20 @@ const PROVIDER_PHONE = {
SMS_OTP_EXP: number().min(0, 'Must be more than 0').required('This is required'),
SMS_OTP_LENGTH: number().min(6, 'Must be 6 or more in length').required('This is required'),
SMS_TEMPLATE: string().required('SMS template is required.'),
+ SMS_TEST_OTP: string()
+ .matches(
+ /^\s*([0-9]{1,15}=[0-9]+)(\s*,\s*[0-9]{1,15}=[0-9]+)*\s*$/g,
+ 'Must be a comma-separated list of <phone number>=<OTP> pairs. Phone numbers should be in international format, without spaces, dashes or the + prefix. Example: 123456789=987654'
+ )
+ .trim()
+ .transform((value: string) => value.replace(/\s+/g, '')),
+ SMS_TEST_OTP_VALID_UNTIL: string().when(['SMS_TEST_OTP'], {
+ is: (SMS_TEST_OTP: string | null) => {
+ return !!SMS_TEST_OTP
+ },
+ then: (schema) => schema.required('You must provide a valid until date.'),
+ otherwise: (schema) => schema.transform((value: string) => ''),
+ }),
}),
misc: {
iconKey: 'phone-icon4',