Skip to content

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

Minor cleanup in sign-in-mfa page.

Ivan Vasilov672fea1fbcfb
diff --git a/studio/components/interfaces/SignIn/SignInMfaForm.tsx b/studio/components/interfaces/SignIn/SignInMfaForm.tsx
index 7647c14b266..c32c6d48ec2 100644
--- a/studio/components/interfaces/SignIn/SignInMfaForm.tsx
+++ b/studio/components/interfaces/SignIn/SignInMfaForm.tsx
@@ -1,7 +1,7 @@
import { AuthError } from '@supabase/gotrue-js'
import { Factor } from '@supabase/supabase-js'
import { useQueryClient } from '@tanstack/react-query'
-import { mfaChallengeAndVerify } from 'data/profile/mfa-challenge-and-verify-mutation'
+import { useMfaChallengeAndVerifyMutation } from 'data/profile/mfa-challenge-and-verify-mutation'
import { useMfaListFactorsQuery } from 'data/profile/mfa-list-factors-query'
import { useStore } from 'hooks'
import { usePushNext } from 'hooks/misc/useAutoAuthRedirect'
@@ -18,6 +18,7 @@ const SignInMfaForm = () => {
const pushNext = usePushNext()
const queryClient = useQueryClient()
const { data: factors, isSuccess: factorsSuccess } = useMfaListFactorsQuery()
+ const { mutateAsync: mfaChallengeAndVerify, isLoading } = useMfaChallengeAndVerifyMutation()
const [selectedFactor, setSelectedFactor] = useState<Factor | null>(null)
// if the user wanders into this page and he has no MFA setup, send the user to the next screen
@@ -37,25 +38,29 @@ const SignInMfaForm = () => {
message: `Signing in...`,
})
if (selectedFactor) {
- try {
- const result = await mfaChallengeAndVerify({ factorId: selectedFactor.id, code })
+ await mfaChallengeAndVerify(
+ { factorId: selectedFactor.id, code },
+ {
+ onSuccess: async () => {
+ ui.setNotification({
+ id: toastId,
+ category: 'success',
+ message: `Signed in successfully!`,
+ })
- ui.setNotification({
- id: toastId,
- category: 'success',
- message: `Signed in successfully!`,
- })
+ await queryClient.resetQueries()
- await queryClient.resetQueries()
-
- await pushNext()
- } catch (error: unknown) {
- ui.setNotification({
- id: toastId,
- category: 'error',
- message: (error as AuthError).message,
- })
- }
+ await pushNext()
+ },
+ onError: (error) => {
+ ui.setNotification({
+ id: toastId,
+ category: 'error',
+ message: (error as AuthError).message,
+ })
+ },
+ }
+ )
}
}
@@ -67,56 +72,54 @@ const SignInMfaForm = () => {
validationSchema={signInSchema}
onSubmit={onSignIn}
>
- {({ isSubmitting }: { isSubmitting: boolean }) => {
- return (
- <div className="flex flex-col gap-4">
- <Input
- id="code"
- name="code"
- type="text"
- icon={<IconLock />}
- placeholder="XXXXXX"
- disabled={isSubmitting}
- autoComplete="off"
- spellCheck="false"
- autoCapitalize="none"
- autoCorrect="off"
- label={
- selectedFactor && factors?.totp.length === 2
- ? `Code generated by ${selectedFactor.friendly_name}`
- : null
- }
- />
+ return (
+ <div className="flex flex-col gap-4">
+ <Input
+ id="code"
+ name="code"
+ type="text"
+ icon={<IconLock />}
+ placeholder="XXXXXX"
+ disabled={isLoading}
+ autoComplete="off"
+ spellCheck="false"
+ autoCapitalize="none"
+ autoCorrect="off"
+ label={
+ selectedFactor && factors?.totp.length === 2
+ ? `Code generated by ${selectedFactor.friendly_name}`
+ : null
+ }
+ />
- <Button
- block
- form="sign-in-mfa-form"
- htmlType="submit"
- size="large"
- disabled={isSubmitting}
- loading={isSubmitting}
- >
- Verify
- </Button>
- {factors?.totp.length === 2 && (
- <div className="text-sm flex flex-col items-center w-full gap-1">
- <div>
- <span className="text-scale-900">Having problems?</span>{' '}
- <a
- className="text-white hover:border-b border-white"
- href="#"
- onClick={() =>
- setSelectedFactor(factors.totp.find((f) => f.id !== selectedFactor?.id)!)
- }
- >{`Authenticate using ${
- factors.totp.find((f) => f.id !== selectedFactor?.id)?.friendly_name
- }?`}</a>
- </div>
- </div>
- )}
+ <Button
+ block
+ form="sign-in-mfa-form"
+ htmlType="submit"
+ size="large"
+ disabled={isLoading}
+ loading={isLoading}
+ >
+ {isLoading ? 'Verifying' : 'Verify'}
+ </Button>
+ {factors?.totp.length === 2 && (
+ <div className="text-sm flex flex-col items-center w-full gap-1">
+ <div>
+ <span className="text-scale-900">Having problems?</span>{' '}
+ <a
+ className="text-white hover:border-b border-white"
+ href="#"
+ onClick={() =>
+ setSelectedFactor(factors.totp.find((f) => f.id !== selectedFactor?.id)!)
+ }
+ >{`Authenticate using ${
+ factors.totp.find((f) => f.id !== selectedFactor?.id)?.friendly_name
+ }?`}</a>
+ </div>
</div>
- )
- }}
+ )}
+ </div>
+ )
</Form>
)
}