[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6P7G0CJ4Q4RMDE19C8E864G":3,"skill-same:01M6P7G0CJ4Q4RMDE19C8E864G":65},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":14,"repositoryHtmlUrl":47,"repositoryHomepageUrl":6,"ownerHtmlUrl":48,"ownerBlogUrl":6,"ownerDescription":49,"updatedAt":50,"install":51,"resources":64},"01M6P7G0CJ4Q4RMDE19C8E864G","two-factor-authentication-best-practices",null,"Implement and review secure two-factor authentication (2FA) using Better Auth's twoFactor plugin.\nUSE FOR: implement secure Better Auth 2FA; add a second verification factor through Better Auth's twoFactor plugin; reject a universal bypass code in Better Auth 2FA; review TOTP, OTP, backup-code, and trusted-device security.\nDO NOT USE FOR: MFA supplied outside Better Auth's twoFactor plugin.","sarthchawla\u002FSetupMyAI","sarthchawla","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F41484686?v=4","01M6P7D22NFMY9MA11Q2YGPKV2","Sarthak Chawla","01M6P7D26JJ9KW98SD1G8BB83R",0,"MIT","https:\u002F\u002Fgithub.com\u002Fsarthchawla\u002FSetupMyAI\u002Fblob\u002Fmain\u002Fpackages\u002Fauth-security\u002Fskills\u002Ftwo-factor-authentication-best-practices\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"factor","authentication","best practices","two factor authentication best practices","mfa","for","add","otp","do","better auth","use","backup","review","verification","code","plugin","secure","auth","implement","security","2026-11-10 10:12:30",false,"---\nname: two-factor-authentication-best-practices\ndescription: |\n  Implement and review secure two-factor authentication (2FA) using Better Auth's twoFactor plugin.\n  USE FOR: implement secure Better Auth 2FA; add a second verification factor through Better Auth's twoFactor plugin; reject a universal bypass code in Better Auth 2FA; review TOTP, OTP, backup-code, and trusted-device security.\n  DO NOT USE FOR: MFA supplied outside Better Auth's twoFactor plugin.\n---\n\n## Setting Up Two-Factor Authentication\n\nWhen adding 2FA to your application, configure the `twoFactor` plugin with your app name as the issuer. This name appears in authenticator apps when users scan the QR code.\n\n```ts\nimport { betterAuth } from \"better-auth\";\nimport { twoFactor } from \"better-auth\u002Fplugins\";\n\nexport const auth = betterAuth({\n  appName: \"My App\", \u002F\u002F Used as the default issuer for TOTP\n  plugins: [\n    twoFactor({\n      issuer: \"My App\", \u002F\u002F Optional: override the app name for 2FA specifically\n    }),\n  ],\n});\n```\n\n**Note**: After adding the plugin, run `npx @better-auth\u002Fcli migrate` to add the required database fields and tables.\n\n### Client-Side Setup\n\nAdd the client plugin and configure the redirect behavior for 2FA verification:\n\n```ts\nimport { createAuthClient } from \"better-auth\u002Fclient\";\nimport { twoFactorClient } from \"better-auth\u002Fclient\u002Fplugins\";\n\nexport const authClient = createAuthClient({\n  plugins: [\n    twoFactorClient({\n      onTwoFactorRedirect() {\n        window.location.href = \"\u002F2fa\"; \u002F\u002F Redirect to your 2FA verification page\n      },\n    }),\n  ],\n});\n```\n\n## Enabling 2FA for Users\n\nWhen a user enables 2FA, require their password for verification. The enable endpoint returns a TOTP URI for QR code generation and backup codes for account recovery.\n\n```ts\nconst enable2FA = async (password: string) => {\n  const { data, error } = await authClient.twoFactor.enable({\n    password,\n  });\n\n  if (data) {\n    \u002F\u002F data.totpURI - Use this to generate a QR code\n    \u002F\u002F data.backupCodes - Display these to the user for safekeeping\n  }\n};\n```\n\n**Important**: The `twoFactorEnabled` flag on the user is not set to `true` until the user successfully verifies their first TOTP code. This ensures users have properly configured their authenticator app before 2FA is fully active.\n\n### Skipping Initial Verification\n\nIf you want to enable 2FA immediately without requiring verification, set `skipVerificationOnEnable`:\n\n```ts\ntwoFactor({\n  skipVerificationOnEnable: true, \u002F\u002F Not recommended for most use cases\n});\n```\n\n**Note**: This is generally not recommended as it doesn't confirm the user has successfully set up their authenticator app.\n\n## TOTP (Authenticator App)\n\nTOTP generates time-based codes using an authenticator app (Google Authenticator, Authy, etc.). Codes are valid for 30 seconds by default.\n\n### Displaying the QR Code\n\nUse the TOTP URI to generate a QR code for users to scan:\n\n```tsx\nimport QRCode from \"react-qr-code\";\n\nconst TotpSetup = ({ totpURI }: { totpURI: string }) => {\n  return \u003CQRCode value={totpURI} \u002F>;\n};\n```\n\n### Verifying TOTP Codes\n\nBetter Auth accepts codes from one period before and one after the current time, accommodating minor clock differences between devices:\n\n```ts\nconst verifyTotp = async (code: string) => {\n  const { data, error } = await authClient.twoFactor.verifyTotp({\n    code,\n    trustDevice: true, \u002F\u002F Optional: remember this device for 30 days\n  });\n};\n```\n\n### TOTP Configuration Options\n\n```ts\ntwoFactor({\n  totpOptions: {\n    digits: 6, \u002F\u002F 6 or 8 digits (default: 6)\n    period: 30, \u002F\u002F Code validity period in seconds (default: 30)\n  },\n});\n```\n\n## OTP (Email\u002FSMS)\n\nOTP sends a one-time code to the user's email or phone. You must implement the `sendOTP` function to deliver codes.\n\n### Configuring OTP Delivery\n\n```ts\nimport { betterAuth } from \"better-auth\";\nimport { twoFactor } from \"better-auth\u002Fplugins\";\nimport { sendEmail } from \".\u002Femail\";\n\nexport const auth = betterAuth({\n  plugins: [\n    twoFactor({\n      otpOptions: {\n        sendOTP: async ({ user, otp }, ctx) => {\n          await sendEmail({\n            to: user.email,\n            subject: \"Your verification code\",\n            text: `Your code is: ${otp}`,\n          });\n        },\n        period: 5, \u002F\u002F Code validity in minutes (default: 3)\n        digits: 6, \u002F\u002F Number of digits (default: 6)\n        allowedAttempts: 5, \u002F\u002F Max verification attempts (default: 5)\n      },\n    }),\n  ],\n});\n```\n\n### Sending and Verifying OTP\n\n```ts\n\u002F\u002F Request an OTP to be sent\nconst sendOtp = async () => {\n  const { data, error } = await authClient.twoFactor.sendOtp();\n};\n\n\u002F\u002F Verify the OTP code\nconst verifyOtp = async (code: string) => {\n  const { data, error } = await authClient.twoFactor.verifyOtp({\n    code,\n    trustDevice: true,\n  });\n};\n```\n\n### OTP Storage Security\n\nConfigure how OTP codes are stored in the database:\n\n```ts\ntwoFactor({\n  otpOptions: {\n    storeOTP: \"encrypted\", \u002F\u002F Options: \"plain\", \"encrypted\", \"hashed\"\n  },\n});\n```\n\nFor custom encryption:\n\n```ts\ntwoFactor({\n  otpOptions: {\n    storeOTP: {\n      encrypt: async (token) => myEncrypt(token),\n      decrypt: async (token) => myDecrypt(token),\n    },\n  },\n});\n```\n\n## Backup Codes\n\nBackup codes provide account recovery when users lose access to their authenticator app or phone. They are generated automatically when 2FA is enabled.\n\n### Displaying Backup Codes\n\nAlways show backup codes to users when they enable 2FA:\n\n```tsx\nconst BackupCodes = ({ codes }: { codes: string[] }) => {\n  return (\n    \u003Cdiv>\n      \u003Cp>Save these codes in a secure location:\u003C\u002Fp>\n      \u003Cul>\n        {codes.map((code, i) => (\n          \u003Cli key={i}>{code}\u003C\u002Fli>\n        ))}\n      \u003C\u002Ful>\n    \u003C\u002Fdiv>\n  );\n};\n```\n\n### Regenerating Backup Codes\n\nWhen users need new codes, regenerate them (this invalidates all previous codes):\n\n```ts\nconst regenerateBackupCodes = async (password: string) => {\n  const { data, error } = await authClient.twoFactor.generateBackupCodes({\n    password,\n  });\n  \u002F\u002F data.backupCodes contains the new codes\n};\n```\n\n### Using Backup Codes for Recovery\n\n```ts\nconst verifyBackupCode = async (code: string) => {\n  const { data, error } = await authClient.twoFactor.verifyBackupCode({\n    code,\n    trustDevice: true,\n  });\n};\n```\n\n**Note**: Each backup code can only be used once and is removed from the database after successful verification.\n\n### Backup Code Configuration\n\n```ts\ntwoFactor({\n  backupCodeOptions: {\n    amount: 10, \u002F\u002F Number of codes to generate (default: 10)\n    length: 10, \u002F\u002F Length of each code (default: 10)\n    storeBackupCodes: \"encrypted\", \u002F\u002F Options: \"plain\", \"encrypted\"\n  },\n});\n```\n\n## Handling 2FA During Sign-In\n\nWhen a user with 2FA enabled signs in, the response includes `twoFactorRedirect: true`:\n\n```ts\nconst signIn = async (email: string, password: string) => {\n  const { data, error } = await authClient.signIn.email(\n    {\n      email,\n      password,\n    },\n    {\n      onSuccess(context) {\n        if (context.data.twoFactorRedirect) {\n          \u002F\u002F Redirect to 2FA verification page\n          window.location.href = \"\u002F2fa\";\n        }\n      },\n    }\n  );\n};\n```\n\n### Server-Side 2FA Detection\n\nWhen using `auth.api.signInEmail` on the server, check for 2FA redirect:\n\n```ts\nconst response = await auth.api.signInEmail({\n  body: {\n    email: \"user@example.com\",\n    password: \"password\",\n  },\n});\n\nif (\"twoFactorRedirect\" in response) {\n  \u002F\u002F Handle 2FA verification\n}\n```\n\n## Trusted Devices\n\nTrusted devices allow users to skip 2FA verification on subsequent sign-ins for a configurable period.\n\n### Enabling Trust on Verification\n\nPass `trustDevice: true` when verifying 2FA:\n\n```ts\nawait authClient.twoFactor.verifyTotp({\n  code: \"123456\",\n  trustDevice: true,\n});\n```\n\n### Configuring Trust Duration\n\n```ts\ntwoFactor({\n  trustDeviceMaxAge: 30 * 24 * 60 * 60, \u002F\u002F 30 days in seconds (default)\n});\n```\n\n**Note**: The trust period refreshes on each successful sign-in within the trust window.\n\n## Security Considerations\n\n### Session Management\n\nDuring the 2FA flow:\n\n1. User signs in with credentials\n2. Session cookie is removed (not yet authenticated)\n3. A temporary two-factor cookie is set (default: 10-minute expiration)\n4. User verifies via TOTP, OTP, or backup code\n5. Session cookie is created upon successful verification\n\nConfigure the two-factor cookie expiration:\n\n```ts\ntwoFactor({\n  twoFactorCookieMaxAge: 600, \u002F\u002F 10 minutes in seconds (default)\n});\n```\n\n### Rate Limiting\n\nBetter Auth applies built-in rate limiting to all 2FA endpoints (3 requests per 10 seconds). For OTP verification, additional attempt limiting is applied:\n\n```ts\ntwoFactor({\n  otpOptions: {\n    allowedAttempts: 5, \u002F\u002F Max attempts per OTP code (default: 5)\n  },\n});\n```\n\n### Encryption at Rest\n\n- TOTP secrets are encrypted using symmetric encryption with your auth secret\n- Backup codes are stored encrypted by default\n- OTP codes can be configured for plain, encrypted, or hashed storage\n\n### Constant-Time Comparison\n\nBetter Auth uses constant-time comparison for OTP verification to prevent timing attacks.\n\n### Credential Account Requirement\n\nTwo-factor authentication can only be enabled for credential (email\u002Fpassword) accounts. For social accounts, assume the external account service already handles 2FA.\n\n## Disabling 2FA\n\nAllow users to disable 2FA with password confirmation:\n\n```ts\nconst disable2FA = async (password: string) => {\n  const { data, error } = await authClient.twoFactor.disable({\n    password,\n  });\n};\n```\n\n**Note**: When 2FA is disabled, trusted device records are revoked.\n\n## Complete Configuration Example\n\n```ts\nimport { betterAuth } from \"better-auth\";\nimport { twoFactor } from \"better-auth\u002Fplugins\";\nimport { sendEmail } from \".\u002Femail\";\n\nexport const auth = betterAuth({\n  appName: \"My App\",\n  plugins: [\n    twoFactor({\n      \u002F\u002F TOTP settings\n      issuer: \"My App\",\n      totpOptions: {\n        digits: 6,\n        period: 30,\n      },\n      \u002F\u002F OTP settings\n      otpOptions: {\n        sendOTP: async ({ user, otp }) => {\n          await sendEmail({\n            to: user.email,\n            subject: \"Your verification code\",\n            text: `Your code is: ${otp}`,\n          });\n        },\n        period: 5,\n        allowedAttempts: 5,\n        storeOTP: \"encrypted\",\n      },\n      \u002F\u002F Backup code settings\n      backupCodeOptions: {\n        amount: 10,\n        length: 10,\n        storeBackupCodes: \"encrypted\",\n      },\n      \u002F\u002F Session settings\n      twoFactorCookieMaxAge: 600, \u002F\u002F 10 minutes\n      trustDeviceMaxAge: 30 * 24 * 60 * 60, \u002F\u002F 30 days\n    }),\n  ],\n});\n```\n","## Setting Up Two-Factor Authentication\n\nWhen adding 2FA to your application, configure the `twoFactor` plugin with your app name as the issuer. This name appears in authenticator apps when users scan the QR code.\n\n```ts\nimport { betterAuth } from \"better-auth\";\nimport { twoFactor } from \"better-auth\u002Fplugins\";\n\nexport const auth = betterAuth({\n  appName: \"My App\", \u002F\u002F Used as the default issuer for TOTP\n  plugins: [\n    twoFactor({\n      issuer: \"My App\", \u002F\u002F Optional: override the app name for 2FA specifically\n    }),\n  ],\n});\n```\n\n**Note**: After adding the plugin, run `npx @better-auth\u002Fcli migrate` to add the required database fields and tables.\n\n### Client-Side Setup\n\nAdd the client plugin and configure the redirect behavior for 2FA verification:\n\n```ts\nimport { createAuthClient } from \"better-auth\u002Fclient\";\nimport { twoFactorClient } from \"better-auth\u002Fclient\u002Fplugins\";\n\nexport const authClient = createAuthClient({\n  plugins: [\n    twoFactorClient({\n      onTwoFactorRedirect() {\n        window.location.href = \"\u002F2fa\"; \u002F\u002F Redirect to your 2FA verification page\n      },\n    }),\n  ],\n});\n```\n\n## Enabling 2FA for Users\n\nWhen a user enables 2FA, require their password for verification. The enable endpoint returns a TOTP URI for QR code generation and backup codes for account recovery.\n\n```ts\nconst enable2FA = async (password: string) => {\n  const { data, error } = await authClient.twoFactor.enable({\n    password,\n  });\n\n  if (data) {\n    \u002F\u002F data.totpURI - Use this to generate a QR code\n    \u002F\u002F data.backupCodes - Display these to the user for safekeeping\n  }\n};\n```\n\n**Important**: The `twoFactorEnabled` flag on the user is not set to `true` until the user successfully verifies their first TOTP code. This ensures users have properly configured their authenticator app before 2FA is fully active.\n\n### Skipping Initial Verification\n\nIf you want to enable 2FA immediately without requiring verification, set `skipVerificationOnEnable`:\n\n```ts\ntwoFactor({\n  skipVerificationOnEnable: true, \u002F\u002F Not recommended for most use cases\n});\n```\n\n**Note**: This is generally not recommended as it doesn't confirm the user has successfully set up their authenticator app.\n\n## TOTP (Authenticator App)\n\nTOTP generates time-based codes using an authenticator app (Google Authenticator, Authy, etc.). Codes are valid for 30 seconds by default.\n\n### Displaying the QR Code\n\nUse the TOTP URI to generate a QR code for users to scan:\n\n```tsx\nimport QRCode from \"react-qr-code\";\n\nconst TotpSetup = ({ totpURI }: { totpURI: string }) => {\n  return \u003CQRCode value={totpURI} \u002F>;\n};\n```\n\n### Verifying TOTP Codes\n\nBetter Auth accepts codes from one period before and one after the current time, accommodating minor clock differences between devices:\n\n```ts\nconst verifyTotp = async (code: string) => {\n  const { data, error } = await authClient.twoFactor.verifyTotp({\n    code,\n    trustDevice: true, \u002F\u002F Optional: remember this device for 30 days\n  });\n};\n```\n\n### TOTP Configuration Options\n\n```ts\ntwoFactor({\n  totpOptions: {\n    digits: 6, \u002F\u002F 6 or 8 digits (default: 6)\n    period: 30, \u002F\u002F Code validity period in seconds (default: 30)\n  },\n});\n```\n\n## OTP (Email\u002FSMS)\n\nOTP sends a one-time code to the user's email or phone. You must implement the `sendOTP` function to deliver codes.\n\n### Configuring OTP Delivery\n\n```ts\nimport { betterAuth } from \"better-auth\";\nimport { twoFactor } from \"better-auth\u002Fplugins\";\nimport { sendEmail } from \".\u002Femail\";\n\nexport const auth = betterAuth({\n  plugins: [\n    twoFactor({\n      otpOptions: {\n        sendOTP: async ({ user, otp }, ctx) => {\n          await sendEmail({\n            to: user.email,\n            subject: \"Your verification code\",\n            text: `Your code is: ${otp}`,\n          });\n        },\n        period: 5, \u002F\u002F Code validity in minutes (default: 3)\n        digits: 6, \u002F\u002F Number of digits (default: 6)\n        allowedAttempts: 5, \u002F\u002F Max verification attempts (default: 5)\n      },\n    }),\n  ],\n});\n```\n\n### Sending and Verifying OTP\n\n```ts\n\u002F\u002F Request an OTP to be sent\nconst sendOtp = async () => {\n  const { data, error } = await authClient.twoFactor.sendOtp();\n};\n\n\u002F\u002F Verify the OTP code\nconst verifyOtp = async (code: string) => {\n  const { data, error } = await authClient.twoFactor.verifyOtp({\n    code,\n    trustDevice: true,\n  });\n};\n```\n\n### OTP Storage Security\n\nConfigure how OTP codes are stored in the database:\n\n```ts\ntwoFactor({\n  otpOptions: {\n    storeOTP: \"encrypted\", \u002F\u002F Options: \"plain\", \"encrypted\", \"hashed\"\n  },\n});\n```\n\nFor custom encryption:\n\n```ts\ntwoFactor({\n  otpOptions: {\n    storeOTP: {\n      encrypt: async (token) => myEncrypt(token),\n      decrypt: async (token) => myDecrypt(token),\n    },\n  },\n});\n```\n\n## Backup Codes\n\nBackup codes provide account recovery when users lose access to their authenticator app or phone. They are generated automatically when 2FA is enabled.\n\n### Displaying Backup Codes\n\nAlways show backup codes to users when they enable 2FA:\n\n```tsx\nconst BackupCodes = ({ codes }: { codes: string[] }) => {\n  return (\n    \u003Cdiv>\n      \u003Cp>Save these codes in a secure location:\u003C\u002Fp>\n      \u003Cul>\n        {codes.map((code, i) => (\n          \u003Cli key={i}>{code}\u003C\u002Fli>\n        ))}\n      \u003C\u002Ful>\n    \u003C\u002Fdiv>\n  );\n};\n```\n\n### Regenerating Backup Codes\n\nWhen users need new codes, regenerate them (this invalidates all previous codes):\n\n```ts\nconst regenerateBackupCodes = async (password: string) => {\n  const { data, error } = await authClient.twoFactor.generateBackupCodes({\n    password,\n  });\n  \u002F\u002F data.backupCodes contains the new codes\n};\n```\n\n### Using Backup Codes for Recovery\n\n```ts\nconst verifyBackupCode = async (code: string) => {\n  const { data, error } = await authClient.twoFactor.verifyBackupCode({\n    code,\n    trustDevice: true,\n  });\n};\n```\n\n**Note**: Each backup code can only be used once and is removed from the database after successful verification.\n\n### Backup Code Configuration\n\n```ts\ntwoFactor({\n  backupCodeOptions: {\n    amount: 10, \u002F\u002F Number of codes to generate (default: 10)\n    length: 10, \u002F\u002F Length of each code (default: 10)\n    storeBackupCodes: \"encrypted\", \u002F\u002F Options: \"plain\", \"encrypted\"\n  },\n});\n```\n\n## Handling 2FA During Sign-In\n\nWhen a user with 2FA enabled signs in, the response includes `twoFactorRedirect: true`:\n\n```ts\nconst signIn = async (email: string, password: string) => {\n  const { data, error } = await authClient.signIn.email(\n    {\n      email,\n      password,\n    },\n    {\n      onSuccess(context) {\n        if (context.data.twoFactorRedirect) {\n          \u002F\u002F Redirect to 2FA verification page\n          window.location.href = \"\u002F2fa\";\n        }\n      },\n    }\n  );\n};\n```\n\n### Server-Side 2FA Detection\n\nWhen using `auth.api.signInEmail` on the server, check for 2FA redirect:\n\n```ts\nconst response = await auth.api.signInEmail({\n  body: {\n    email: \"user@example.com\",\n    password: \"password\",\n  },\n});\n\nif (\"twoFactorRedirect\" in response) {\n  \u002F\u002F Handle 2FA verification\n}\n```\n\n## Trusted Devices\n\nTrusted devices allow users to skip 2FA verification on subsequent sign-ins for a configurable period.\n\n### Enabling Trust on Verification\n\nPass `trustDevice: true` when verifying 2FA:\n\n```ts\nawait authClient.twoFactor.verifyTotp({\n  code: \"123456\",\n  trustDevice: true,\n});\n```\n\n### Configuring Trust Duration\n\n```ts\ntwoFactor({\n  trustDeviceMaxAge: 30 * 24 * 60 * 60, \u002F\u002F 30 days in seconds (default)\n});\n```\n\n**Note**: The trust period refreshes on each successful sign-in within the trust window.\n\n## Security Considerations\n\n### Session Management\n\nDuring the 2FA flow:\n\n1. User signs in with credentials\n2. Session cookie is removed (not yet authenticated)\n3. A temporary two-factor cookie is set (default: 10-minute expiration)\n4. User verifies via TOTP, OTP, or backup code\n5. Session cookie is created upon successful verification\n\nConfigure the two-factor cookie expiration:\n\n```ts\ntwoFactor({\n  twoFactorCookieMaxAge: 600, \u002F\u002F 10 minutes in seconds (default)\n});\n```\n\n### Rate Limiting\n\nBetter Auth applies built-in rate limiting to all 2FA endpoints (3 requests per 10 seconds). For OTP verification, additional attempt limiting is applied:\n\n```ts\ntwoFactor({\n  otpOptions: {\n    allowedAttempts: 5, \u002F\u002F Max attempts per OTP code (default: 5)\n  },\n});\n```\n\n### Encryption at Rest\n\n- TOTP secrets are encrypted using symmetric encryption with your auth secret\n- Backup codes are stored encrypted by default\n- OTP codes can be configured for plain, encrypted, or hashed storage\n\n### Constant-Time Comparison\n\nBetter Auth uses constant-time comparison for OTP verification to prevent timing attacks.\n\n### Credential Account Requirement\n\nTwo-factor authentication can only be enabled for credential (email\u002Fpassword) accounts. For social accounts, assume the external account service already handles 2FA.\n\n## Disabling 2FA\n\nAllow users to disable 2FA with password confirmation:\n\n```ts\nconst disable2FA = async (password: string) => {\n  const { data, error } = await authClient.twoFactor.disable({\n    password,\n  });\n};\n```\n\n**Note**: When 2FA is disabled, trusted device records are revoked.\n\n## Complete Configuration Example\n\n```ts\nimport { betterAuth } from \"better-auth\";\nimport { twoFactor } from \"better-auth\u002Fplugins\";\nimport { sendEmail } from \".\u002Femail\";\n\nexport const auth = betterAuth({\n  appName: \"My App\",\n  plugins: [\n    twoFactor({\n      \u002F\u002F TOTP settings\n      issuer: \"My App\",\n      totpOptions: {\n        digits: 6,\n        period: 30,\n      },\n      \u002F\u002F OTP settings\n      otpOptions: {\n        sendOTP: async ({ user, otp }) => {\n          await sendEmail({\n            to: user.email,\n            subject: \"Your verification code\",\n            text: `Your code is: ${otp}`,\n          });\n        },\n        period: 5,\n        allowedAttempts: 5,\n        storeOTP: \"encrypted\",\n      },\n      \u002F\u002F Backup code settings\n      backupCodeOptions: {\n        amount: 10,\n        length: 10,\n        storeBackupCodes: \"encrypted\",\n      },\n      \u002F\u002F Session settings\n      twoFactorCookieMaxAge: 600, \u002F\u002F 10 minutes\n      trustDeviceMaxAge: 30 * 24 * 60 * 60, \u002F\u002F 30 days\n    }),\n  ],\n});\n```\n",{"name":5,"description":7},"main","3934845b800ff514cb89eb81d43f3dc4cbf51ff2","packages\u002Fauth-security\u002Fskills\u002Ftwo-factor-authentication-best-practices","https:\u002F\u002Fgithub.com\u002Fsarthchawla\u002FSetupMyAI","https:\u002F\u002Fgithub.com\u002Fsarthchawla","there ain't no problem i can't solve","2026-10-23 01:26:57",{"source":8,"skillName":5,"commands":52,"prompt":62,"zipAvailable":63},[53,56,59],{"tool":54,"command":55},"npx","npx skills add sarthchawla\u002FSetupMyAI --skill two-factor-authentication-best-practices",{"tool":57,"command":58},"bunx","bunx skills add sarthchawla\u002FSetupMyAI --skill two-factor-authentication-best-practices",{"tool":60,"command":61},"pnpm","pnpm dlx skills add sarthchawla\u002FSetupMyAI --skill two-factor-authentication-best-practices","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fsarthchawla\u002FSetupMyAI\u002Fblob\u002Fmain\u002Fpackages\u002Fauth-security\u002Fskills\u002Ftwo-factor-authentication-best-practices\u002FSKILL.md",true,[],[66,74,89,98,108,128],{"skillNo":67,"name":68,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":39},"01M6P8953HNC422WFQSPP2FMQE","sample-skill","https:\u002F\u002Fgithub.com\u002Fsarthchawla\u002FSetupMyAI\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fmock-repo\u002F.claude\u002Fskills\u002Fsample-skill\u002FSKILL.md",[],[72,73],"sample","sample skill",{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":39},"01M6P8924ZSDAZ88Y5Q9P3KAQV","synthetic-review-candidate","Candidate for smoke testing an evaluation runner only.","https:\u002F\u002Fgithub.com\u002Fsarthchawla\u002FSetupMyAI\u002Fblob\u002Fmain\u002Fscripts\u002Fskill-eval\u002Ffixtures\u002Fcandidate\u002FSKILL.md",[],[81,82,83,31,84,85,86,87,88,24],"synthetic review candidate","candidate","synthetic","only","testing","Evaluation","smoke","runner",{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":39},"01M6P88FEGGNH8EZY0PDHD9KQA","synthetic-review-baseline","Baseline for smoke testing an evaluation runner only.","https:\u002F\u002Fgithub.com\u002Fsarthchawla\u002FSetupMyAI\u002Fblob\u002Fmain\u002Fscripts\u002Fskill-eval\u002Ffixtures\u002Fbaseline\u002FSKILL.md",[],[96,83,97,31,87,88,24,84,85,86],"synthetic review baseline","baseline",{"skillNo":99,"name":31,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":39},"01M6P87ZXVEHRM860960DB5FEQ","Run the existing user-invoked review bundle and independently adjudicate its findings.","https:\u002F\u002Fgithub.com\u002Fsarthchawla\u002FSetupMyAI\u002Fblob\u002Fmain\u002Fpackages\u002Funiversal\u002Fskills\u002Freview\u002FSKILL.md",[],[31,104,105,106,107],"run","user","bundle","Existing",{"skillNo":109,"name":110,"nameZh":6,"description":111,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":112,"categories":113,"keywords":114,"publishedAt":39},"01M6P87FC73MZTRB6ZBP4GR1VQ","review-adjudication","Verify generated or human review findings before fixing, defending, replying, resolving, or reusing them as learned guidance. Use within a review, review-comment fix, monitor, or readiness workflow.","https:\u002F\u002Fgithub.com\u002Fsarthchawla\u002FSetupMyAI\u002Fblob\u002Fmain\u002Fpackages\u002Funiversal\u002Fskills\u002Freview-adjudication\u002FSKILL.md",[],[115,31,116,117,118,119,120,121,122,123,124,125,29,126,127],"review adjudication","workflow","generated","human review","guidance","human","as","readiness","learned","review findings","fix","verify","monitor",{"skillNo":129,"name":130,"nameZh":6,"description":131,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":132,"categories":133,"keywords":134,"publishedAt":39},"01M6P871Q44KQES293T60JQETA","monitor-mr","Monitor review findings and CI using the shared adjudication procedure.","https:\u002F\u002Fgithub.com\u002Fsarthchawla\u002FSetupMyAI\u002Fblob\u002Fmain\u002Fpackages\u002Funiversal\u002Fskills\u002Fmonitor-mr\u002FSKILL.md",[],[127,135,136,124,137,138,31],"mr","monitor mr","shared","ci"]