Skip to content

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

fix(studio): toggle secret visibility independently in edge function secrets (#41487)

Vaibhav7981846a0e6e
diff --git a/apps/studio/components/interfaces/Functions/EdgeFunctionSecrets/AddNewSecretForm.tsx b/apps/studio/components/interfaces/Functions/EdgeFunctionSecrets/AddNewSecretForm.tsx
index 07ae0b379ab..ad744820885 100644
--- a/apps/studio/components/interfaces/Functions/EdgeFunctionSecrets/AddNewSecretForm.tsx
+++ b/apps/studio/components/interfaces/Functions/EdgeFunctionSecrets/AddNewSecretForm.tsx
@@ -57,7 +57,7 @@ const removeWrappingQuotes = (str: string): string => {
const AddNewSecretForm = () => {
const { ref: projectRef } = useParams()
- const [showSecretValue, setShowSecretValue] = useState(false)
+ const [visibleSecrets, setVisibleSecrets] = useState<Set<string>>(new Set())
const [duplicateSecretName, setDuplicateSecretName] = useState<string>('')
const [pendingSecrets, setPendingSecrets] = useState<z.infer<typeof FormSchema> | null>(null)
@@ -130,7 +130,10 @@ const AddNewSecretForm = () => {
onSuccess: (_, variables) => {
toast.success(`Successfully created new secret "${variables.secrets[0].name}"`)
// RHF recommends using setTimeout/useEffect to reset the form
- setTimeout(() => form.reset(), 0)
+ setTimeout(() => {
+ form.reset()
+ setVisibleSecrets(new Set())
+ }, 0)
},
})
@@ -161,6 +164,38 @@ const AddNewSecretForm = () => {
setPendingSecrets(null)
}
+ const handleToggleSecretVisibility = (fieldId: string) => {
+ setVisibleSecrets((prev) => {
+ const visibleSet = new Set(prev)
+ if (visibleSet.has(fieldId)) {
+ visibleSet.delete(fieldId)
+ } else {
+ visibleSet.add(fieldId)
+ }
+ return visibleSet
+ })
+ }
+
+ const handleRemoveSecret = (fieldId: string, index: number) => {
+ if (fields.length > 1) {
+ setVisibleSecrets((prev) => {
+ const visibleSet = new Set(prev)
+ visibleSet.delete(fieldId)
+ return visibleSet
+ })
+ remove(index)
+ } else {
+ form.reset(defaultValues)
+ setVisibleSecrets(new Set())
+ }
+ }
+
+ const handleAddAnotherSecret = () => {
+ append({ name: '', value: '' })
+ }
+
+ const isSecretVisible = (fieldId: string) => visibleSecrets.has(fieldId)
+
return (
<>
<Form_Shadcn_ {...form}>
@@ -198,7 +233,7 @@ const AddNewSecretForm = () => {
<FormControl_Shadcn_>
<Input
{...field}
- type={showSecretValue ? 'text' : 'password'}
+ type={isSecretVisible(fieldItem.id) ? 'text' : 'password'}
data-1p-ignore
data-lpignore="true"
data-form-type="other"
@@ -208,8 +243,8 @@ const AddNewSecretForm = () => {
<Button
type="text"
className="px-1"
- icon={showSecretValue ? <EyeOff /> : <Eye />}
- onClick={() => setShowSecretValue(!showSecretValue)}
+ icon={isSecretVisible(fieldItem.id) ? <EyeOff /> : <Eye />}
+ onClick={() => handleToggleSecretVisibility(fieldItem.id)}
/>
</div>
}
@@ -225,29 +260,17 @@ const AddNewSecretForm = () => {
className="h-[34px] mt-6"
icon={<MinusCircle />}
disabled={fields.length <= 1}
- onClick={() => (fields.length > 1 ? remove(index) : form.reset(defaultValues))}
+ onClick={() => handleRemoveSecret(fieldItem.id, index)}
/>
</div>
))}
- <Button
- type="default"
- onClick={() => {
- const formValues = form.getValues('secrets')
- const isEmptyForm = formValues.every((field) => !field.name && !field.value)
- if (isEmptyForm) {
- fields.forEach((_, index) => remove(index))
- append({ name: '', value: '' })
- } else {
- append({ name: '', value: '' })
- }
- }}
- >
+ <Button type="default" onClick={handleAddAnotherSecret}>
Add another
</Button>
</CardContent>
<CardFooter className="justify-between space-x-2">
- <p className="text-sm text-foreground-lighter">
+ <p className="text-sm text-foreground-muted">
Insert or update multiple secrets at once by pasting key-value pairs
</p>