The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
add optional flag on whether to refresh factors in challenge and verify mutation, call that flag false when signing in mfa
Joshen Lim15818116b9c5
diff --git a/studio/components/interfaces/SignIn/SignInMfaForm.tsx b/studio/components/interfaces/SignIn/SignInMfaForm.tsxindex 759b3437d1c..abce02cdeeb 100644--- a/studio/components/interfaces/SignIn/SignInMfaForm.tsx+++ b/studio/components/interfaces/SignIn/SignInMfaForm.tsx@@ -66,7 +66,7 @@ const SignInMfaForm = () => {})if (selectedFactor) {await mfaChallengeAndVerify(- { factorId: selectedFactor.id, code },+ { factorId: selectedFactor.id, code, refreshFactors: false },{onSuccess: async () => {ui.setNotification({diff --git a/studio/data/profile/mfa-challenge-and-verify-mutation.ts b/studio/data/profile/mfa-challenge-and-verify-mutation.tsindex 21d8c721f8a..7edd05daefe 100644--- a/studio/data/profile/mfa-challenge-and-verify-mutation.ts+++ b/studio/data/profile/mfa-challenge-and-verify-mutation.ts@@ -3,9 +3,12 @@ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/reactimport { auth } from 'lib/gotrue'import { profileKeys } from './keys'+interface MFAChallengeAndVerifyVariables extends MFAChallengeAndVerifyParams {+ refreshFactors?: boolean+}+export const mfaChallengeAndVerify = async (params: MFAChallengeAndVerifyParams) => {const { error, data } = await auth.mfa.challengeAndVerify(params)-if (error) throw errorreturn data}@@ -17,21 +20,29 @@ export const useMfaChallengeAndVerifyMutation = ({onSuccess,...options}: Omit<- UseMutationOptions<CustomMFAVerifyResponse, CustomMFAVerifyError, MFAChallengeAndVerifyParams>,+ UseMutationOptions<CustomMFAVerifyResponse, CustomMFAVerifyError, MFAChallengeAndVerifyVariables>,'mutationFn'> = {}) => {const queryClient = useQueryClient()- return useMutation((vars) => mfaChallengeAndVerify(vars), {- async onSuccess(data, variables, context) {- // when a MFA is added, the aaLevel is bumped up- await Promise.all([- queryClient.invalidateQueries(profileKeys.mfaFactors()),- queryClient.invalidateQueries(profileKeys.aaLevel()),- ])-- await onSuccess?.(data, variables, context)+ return useMutation(+ (vars) => {+ const { refreshFactors, ...params } = vars+ return mfaChallengeAndVerify(params)},- ...options,- })+ {+ async onSuccess(data, variables, context) {+ // when a MFA is added, the aaLevel is bumped up+ const refreshFactors = variables.refreshFactors ?? true++ await Promise.all([+ ...(refreshFactors ? [queryClient.invalidateQueries(profileKeys.mfaFactors())] : []),+ queryClient.invalidateQueries(profileKeys.aaLevel()),+ ])++ await onSuccess?.(data, variables, context)+ },+ ...options,+ }+ )}