Skip to content
Closed

Qr #65

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,14 @@ exports.getTotpSetup = async (req, res, next) => {
secret,
});
req.session.totpSecret = secret.base32;
// Generate QR image (SVG) data URI using the `qr` package
const qrModule = await import('qr');
const encodeQR = qrModule.default || qrModule;
Comment on lines +974 to +975
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await import('qr') is executed inside the request handler. Even though Node caches modules, doing this per request adds async overhead and can surface runtime import failures only when this route is hit. Prefer importing once at module scope (or memoizing the import) so failures happen at startup and the handler stays synchronous aside from DB work.

Copilot uses AI. Check for mistakes.
const svg = encodeQR(totp.toString(), 'svg');
const qrImage = `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
res.render('account/totp-setup', {
title: 'Setup Authenticator',
qrCode: totp.toString(),
qrImage,
Comment on lines +973 to +980
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a new QR generation code path for the TOTP setup page, but there doesn’t appear to be test coverage asserting the page renders a QR image (e.g., an authenticated request expecting qrImage/data:image/svg+xml in the response). Adding an integration test for the authenticated /account/2fa/totp/setup route would help catch runtime issues with the qr dependency and SVG/data-URI generation.

Copilot uses AI. Check for mistakes.
secret: secret.base32,
});
} catch (err) {
Expand Down
Loading
Loading