Files
supabase/apps/studio/lib/account-recovery/evaluate-account-recovery.ts
Danny White 5cf3cf1032 feat(studio): make security the home for sign-in and recovery setup (#52358)
## Problem

- Sign-in methods are in Preferences, separate from MFA and recovery
settings.
- The risk of a single sign-in method (e.g. GitHub, and getting locked
out of that account) isn’t clearly communicated.

## Solution

- Bring sign-in methods, MFA and recovery codes together on the Security
page. If Security is disabled, sign-in methods remain accessible in
Preferences.
- Highlight the most important next step with a primary button. For
example, when MFA is off, “Set up MFA” takes priority over adding a
password.
- Explain the risk of relying on a single sign-in provider, and make it
clear which email address a new password will apply to.
- After connecting a sign-in provider, return users to the settings page
they can access. Links to password setup open the password dialog
directly.

| After |
| --- |
| <img width="1460" height="1426" alt="CleanShot 2026-11-06 at 14 54
23@2x"
src="https://github.com/user-attachments/assets/afb82601-1b6f-43be-9e98-a0edb8d529c8"
/> |
| _The “Sign-in methods” section moved to Account → Security. Note also
the new Admonition regarding the risk of a single (GitHub) sign-in
method._ |

## Review instructions

1. Open
[Security](https://studio-staging-git-dnywh-recovery-security-home-supabase.vercel.app/dashboard/account/security#sign-in-methods).
Check sign-in methods appear above MFA and recovery codes. With MFA off,
“Set up MFA” should be primary.
2. Open Preferences. Sign-in methods should be absent unless Security is
disabled.
3. On a test account, check password setup, email editing and provider
linking. [Open password setup
directly](https://studio-staging-git-dnywh-recovery-security-home-supabase.vercel.app/dashboard/account/security?securityAction=set-password#sign-in-methods),
then cancel and confirm it stays closed.
2026-11-09 17:42:43 +11:00

82 lines
2.4 KiB
TypeScript

import { isSingleOAuthIdentity } from './single-oauth-identity'
export type AccountRecoveryFinding = {
id:
| 'recovery-codes-missing'
| 'recovery-codes-exhausted'
| 'recovery-codes-low'
| 'single-mfa-factor'
| 'single-oauth-identity'
severity: 'critical' | 'warning' | 'info'
action: 'generate-codes' | 'regenerate-codes' | 'set-password' | 'add-factor'
remainingCodes?: number
}
export type AccountRecoveryInput = {
identities: { provider: string }[]
email?: string
verifiedFactorCount: number
recoveryCodes:
| { status: 'unknown' }
| { status: 'missing' }
| { status: 'available'; remaining: number }
features: {
recoveryCodesEnabled: boolean
passwordEnabled: boolean
}
}
export const evaluateAccountRecovery = ({
identities,
email,
verifiedFactorCount,
recoveryCodes,
features,
}: AccountRecoveryInput): AccountRecoveryFinding[] => {
if (identities.some((identity) => identity.provider.startsWith('sso'))) return []
const findings: AccountRecoveryFinding[] = []
const hasOneFactor = verifiedFactorCount === 1
let hasCodeFinding = false
if (features.recoveryCodesEnabled && verifiedFactorCount > 0) {
if (recoveryCodes.status === 'missing') {
findings.push({
id: 'recovery-codes-missing',
severity: 'warning',
action: 'generate-codes',
})
hasCodeFinding = true
} else if (recoveryCodes.status === 'available' && hasOneFactor) {
if (recoveryCodes.remaining === 0) {
findings.push({
id: 'recovery-codes-exhausted',
severity: 'critical',
action: 'regenerate-codes',
remainingCodes: 0,
})
hasCodeFinding = true
} else if (recoveryCodes.remaining >= 1 && recoveryCodes.remaining <= 3) {
findings.push({
id: 'recovery-codes-low',
severity: 'warning',
action: 'regenerate-codes',
remainingCodes: recoveryCodes.remaining,
})
hasCodeFinding = true
}
}
}
const isCodeStatusUnknown = features.recoveryCodesEnabled && recoveryCodes.status === 'unknown'
if (hasOneFactor && !hasCodeFinding && !isCodeStatusUnknown) {
findings.push({ id: 'single-mfa-factor', severity: 'info', action: 'add-factor' })
}
if (features.passwordEnabled && isSingleOAuthIdentity({ identities, email })) {
findings.push({ id: 'single-oauth-identity', severity: 'warning', action: 'set-password' })
}
return findings
}