@mindfulauth/core 2.0.0-beta.8 → 2.0.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,41 +6,6 @@
|
|
|
6
6
|
// Security Settings Script - Astro Optimized
|
|
7
7
|
// Combines: Change Password + 2FA Management + Add Authentication Method
|
|
8
8
|
|
|
9
|
-
// ============================================================================
|
|
10
|
-
// QRCODE DYNAMIC LOADING (bundled via qrcode npm package)
|
|
11
|
-
// ============================================================================
|
|
12
|
-
|
|
13
|
-
// Capture CDN origin at load time for loading co-hosted libraries
|
|
14
|
-
const __cdnOrigin = (() => {
|
|
15
|
-
try {
|
|
16
|
-
if (document.currentScript && document.currentScript.src) {
|
|
17
|
-
return new URL(document.currentScript.src).origin;
|
|
18
|
-
}
|
|
19
|
-
} catch (_) {}
|
|
20
|
-
return '';
|
|
21
|
-
})();
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Dynamically loads the bundled QRCode library from the same CDN origin.
|
|
25
|
-
* Uses the qrcode npm package (bundled as IIFE via esbuild).
|
|
26
|
-
* Exposes QRCode.toCanvas(), QRCode.toDataURL(), QRCode.toString()
|
|
27
|
-
* @returns {Promise<void>}
|
|
28
|
-
*/
|
|
29
|
-
async function loadQRCodeLibrary() {
|
|
30
|
-
return new Promise((resolve, reject) => {
|
|
31
|
-
if (typeof QRCode !== 'undefined' && QRCode.toCanvas) {
|
|
32
|
-
resolve();
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const script = document.createElement('script');
|
|
37
|
-
script.src = `${__cdnOrigin}/lib/qrcode.js`;
|
|
38
|
-
script.onload = () => resolve();
|
|
39
|
-
script.onerror = () => reject(new Error('Failed to load QR code library'));
|
|
40
|
-
document.head.appendChild(script);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
9
|
// ============================================================================
|
|
45
10
|
// RECORDID EXTRACTION HELPER
|
|
46
11
|
// ============================================================================
|
|
@@ -210,22 +175,20 @@ function init2FA() {
|
|
|
210
175
|
setupDiv.removeAttribute('hidden');
|
|
211
176
|
setupDiv.classList && setupDiv.classList.remove('hidden');
|
|
212
177
|
setupDiv.style.display = 'flex';
|
|
213
|
-
qrCodeContainer.
|
|
178
|
+
qrCodeContainer.replaceChildren();
|
|
214
179
|
|
|
215
|
-
messageEl.textContent = '
|
|
180
|
+
messageEl.textContent = 'Generating QR code...';
|
|
216
181
|
try {
|
|
217
|
-
// Load QRCode library dynamically
|
|
218
|
-
await loadQRCodeLibrary();
|
|
219
|
-
|
|
220
|
-
messageEl.textContent = 'Generating secret key...';
|
|
221
182
|
const response = await window.apiFetch('/auth/setup-2fa', { body: JSON.stringify({ recordid }) });
|
|
222
183
|
const result = await response.json();
|
|
223
184
|
if (result.success) {
|
|
224
|
-
qrCodeContainer.
|
|
185
|
+
qrCodeContainer.replaceChildren();
|
|
225
186
|
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
187
|
+
const img = document.createElement('img');
|
|
188
|
+
img.src = result.qrCodeDataUrl;
|
|
189
|
+
img.width = 256;
|
|
190
|
+
img.alt = 'QR code for authenticator app';
|
|
191
|
+
qrCodeContainer.appendChild(img);
|
|
229
192
|
|
|
230
193
|
messageEl.textContent = 'Scan the QR code with your authenticator app and enter the code below.';
|
|
231
194
|
} else {
|
|
@@ -265,7 +228,7 @@ function init2FA() {
|
|
|
265
228
|
messageEl.textContent = result.message;
|
|
266
229
|
|
|
267
230
|
if (result.recoveryCodes && result.recoveryCodes.length > 0) {
|
|
268
|
-
recoveryList.
|
|
231
|
+
recoveryList.replaceChildren();
|
|
269
232
|
result.recoveryCodes.forEach(code => {
|
|
270
233
|
const li = document.createElement('li');
|
|
271
234
|
li.textContent = code;
|