Skip to content

Commit 71acf22

Browse files
authored
Skip invalidating auth config when toggling security email notification in template editor page (supabase#44888)
## Context Preferred fix to this PR [here](supabase#44886) On a security email template page (e.g. Reauthentication), if you edit the Subject or Body without saving, then toggle **Enable notification** in the Configuration card and click **Save changes**, the Content edits are reverted to the last saved values. ## Changes involved Opting to not invalidate the `authConfig` RQ cache on a successful mutation when toggling the security email notification while on the template editor page ## To test - [ ] Open a security email template - [ ] Make some changes to the template without saving - [ ] Toggle the notification and save - [ ] Ensure that the template changes are still present and not reverted <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Optimized query cache handling for authentication configuration updates to reduce unnecessary refresh operations. * Enhanced type safety for form submissions in authentication settings to prevent data validation errors. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 5715334 commit 71acf22

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

apps/studio/data/auth/auth-config-update-mutation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { ResponseError, UseCustomMutationOptions } from '@/types'
1010
export type AuthConfigUpdateVariables = {
1111
projectRef: string
1212
config: Partial<components['schemas']['UpdateGoTrueConfigBody']>
13+
skipInvalidation?: boolean
1314
}
1415

1516
export async function updateAuthConfig({ projectRef, config }: AuthConfigUpdateVariables) {
@@ -41,9 +42,10 @@ export const useAuthConfigUpdateMutation = ({
4142
return useMutation<AuthConfigUpdateData, ResponseError, AuthConfigUpdateVariables>({
4243
mutationFn: (vars) => updateAuthConfig(vars),
4344
async onSuccess(data, variables, context) {
44-
const { projectRef } = variables
45+
const { projectRef, skipInvalidation = false } = variables
4546
await Promise.all([
46-
queryClient.invalidateQueries({ queryKey: authKeys.authConfig(projectRef) }),
47+
!skipInvalidation &&
48+
queryClient.invalidateQueries({ queryKey: authKeys.authConfig(projectRef) }),
4749
queryClient.invalidateQueries({ queryKey: lintKeys.lint(projectRef) }),
4850
])
4951
await queryClient.refetchQueries({

apps/studio/pages/project/[ref]/auth/templates/[templateId].tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ const RedirectToTemplates = () => {
127127
defaultValues,
128128
})
129129

130-
const onSubmit = (values: any) => {
130+
const onSubmit = (values: z.infer<typeof TemplateFormSchema>) => {
131131
if (!projectRef) return console.error('Project ref is required')
132-
updateAuthConfig({ projectRef: projectRef, config: { ...values } })
132+
updateAuthConfig({ projectRef: projectRef, config: { ...values }, skipInvalidation: true })
133133
}
134134

135135
useEffect(() => {

0 commit comments

Comments
 (0)