mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Context In Authentication -> Multi Factor, if you've set SMS MFA to any status apart from "Disabled" and refresh the page, the UI seemingly doesn't render the right value in the dropdown as such: <img width="1114" height="160" alt="image" src="https://github.com/user-attachments/assets/d3353628-0b9a-4347-b81f-3a968a87b5c2" /> Was happening as the form mounted with placeholder values (for SMS MFA, default status was "Disabled"), and the real value was only applied afterwards by a `useEffect` which called `reset`. This changed the `Select`'s value after mount, in Radix then fires an event on that change through `onValueChange` which set `value` as an empty string `''`. It happens as well for TOTP, if you set any value other than "Enabled" which is the default status. ## Changes involved - Am also opting to breakdown `MfaAuthSettingsForm.tsx` into smaller components as it's a single file handling 3 different forms at the moment - (Main fix) Derive the form values via `defaultValue` instead of via `useEffect` which prevents the unintended firing of `onValueChange` for the `Select`
27 lines
719 B
TypeScript
27 lines
719 B
TypeScript
export function determineMFAStatus(verifyEnabled: boolean, enrollEnabled: boolean) {
|
|
return verifyEnabled ? (enrollEnabled ? 'Enabled' : 'Verify Enabled') : 'Disabled'
|
|
}
|
|
|
|
export const MFAFactorSelectionOptions = [
|
|
{
|
|
label: 'Enabled',
|
|
value: 'Enabled',
|
|
},
|
|
{
|
|
label: 'Verify Enabled',
|
|
value: 'Verify Enabled',
|
|
},
|
|
{
|
|
label: 'Disabled',
|
|
value: 'Disabled',
|
|
},
|
|
]
|
|
|
|
export const MfaStatusToState = (status: (typeof MFAFactorSelectionOptions)[number]['value']) => {
|
|
return status === 'Enabled'
|
|
? { verifyEnabled: true, enrollEnabled: true }
|
|
: status === 'Verify Enabled'
|
|
? { verifyEnabled: true, enrollEnabled: false }
|
|
: { verifyEnabled: false, enrollEnabled: false }
|
|
}
|