🚀 新規事業

two-factor-auth

最終更新 2026年05月08日 / 40_新規事業/SCALE_Build/カタログ/基本装備集/two-factor-auth.md

2要素認証(TOTP)

何のために?

パスワード漏洩しても突破されない。CRM・経理系は必須レベル。

どう実装する?

speakeasy で TOTP secret 生成 → QRコード表示 → 6桁コード検証。

コード例

import speakeasy from 'speakeasy';
import qrcode from 'qrcode';

// セットアップ
const secret = ●●●●●●({ name: 'SCALE CRM (user@example.com)' });
const qrUrl = await qrcode.toDataURL(secret●●●●●●);
// secret●●●●●● を DB に保存

// ログイン時の検証
const ok = speakeasy.totp.verify({
  secret: ●●●●●●,
  encoding: 'base32',
  token: ●●●●●●,
  window: 1,
});