Skip to content

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

Redirect to MFA if the user is logging in via email and has MFA setup.

Ivan Vasilov7ac94601041b
diff --git a/studio/components/interfaces/SignIn/SignInForm.tsx b/studio/components/interfaces/SignIn/SignInForm.tsx
index 934b401e21e..c58d2351751 100644
--- a/studio/components/interfaces/SignIn/SignInForm.tsx
+++ b/studio/components/interfaces/SignIn/SignInForm.tsx
@@ -1,14 +1,17 @@
import HCaptcha from '@hcaptcha/react-hcaptcha'
+import * as Sentry from '@sentry/nextjs'
+import { AuthError } from '@supabase/supabase-js'
import { useQueryClient } from '@tanstack/react-query'
+import { getMfaAuthenticatorAssuranceLevel } from 'data/profile/mfa-authenticator-assurance-level-query'
import { useStore } from 'hooks'
import { usePushNext } from 'hooks/misc/useAutoAuthRedirect'
import { auth } from 'lib/gotrue'
import { incrementSignInClicks } from 'lib/local-storage'
import Link from 'next/link'
+import { useRouter } from 'next/router'
import { useRef, useState } from 'react'
import { Button, Form, Input } from 'ui'
import { object, string } from 'yup'
-import * as Sentry from '@sentry/nextjs'
const signInSchema = object({
email: string().email('Must be a valid email').required('Email is required'),
@@ -17,6 +20,7 @@ const signInSchema = object({
const SignInForm = () => {
const { ui } = useStore()
+ const router = useRouter()
const pushNext = usePushNext()
const queryClient = useQueryClient()
@@ -47,15 +51,36 @@ const SignInForm = () => {
Sentry.captureMessage('Sign in without previous sign out detected')
}
- ui.setNotification({
- id: toastId,
- category: 'success',
- message: `Signed in successfully!`,
- })
+ try {
+ const data = await getMfaAuthenticatorAssuranceLevel()
+ if (data) {
+ if (data.currentLevel !== data.nextLevel) {
+ ui.setNotification({
+ id: toastId,
+ category: 'success',
+ message: `You need to provide your second factor authentication.`,
+ })
+ router.replace('/sign-in-mfa')
+ return
+ }
+ }
+
+ ui.setNotification({
+ id: toastId,
+ category: 'success',
+ message: `Signed in successfully!`,
+ })
- await queryClient.resetQueries()
+ await queryClient.resetQueries()
- await pushNext()
+ await pushNext()
+ } catch (error) {
+ ui.setNotification({
+ id: toastId,
+ category: 'error',
+ message: (error as AuthError).message,
+ })
+ }
} else {
setCaptchaToken(null)
captchaRef.current?.resetCaptcha()