Skip to content

Commit 742d560

Browse files
authored
Merge branch 'main' into feature/AdminForth/1540/show-proper-error-messages-to-
2 parents dcf0bea + 80748d4 commit 742d560

5 files changed

Lines changed: 51 additions & 47 deletions

File tree

custom/TwoFAModal.vue

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
{{$t('Having trouble?')}}
4242
<button type="button" class="af-2fa-switch-to-passkey text-lightPrimary dark:text-white hover:underline cursor-pointer" @click="modalMode = 'passkey'">{{$t('Use passkey instead')}}</button>
4343
</p>
44-
<p class="af-2fa-multiple-actions text-center text-red-500 text-xs" v-if="sessionsIdsToResolve.length > 1"> You are confirming {{ sessionsIdsToResolve.length }} actions</p>
44+
<p class="af-2fa-multiple-actions text-center text-red-500 text-xs" v-if="sessionsIdsToResolve.length > 1">
45+
{{ $t('You are confirming {count} action | You are confirming {count} actions', sessionsIdsToResolve.length) }}
46+
</p>
4547
</div>
4648

4749
<div v-else-if="modalMode === 'passkey'" class="af-two-factor-modal-passkeys flex flex-col gap-4 relative bg-white dark:bg-gray-700 rounded-lg shadow p-6 w-full max-w-md">
@@ -89,7 +91,9 @@
8991
{{$t('Having trouble?')}}
9092
<button type="button" class="af-2fa-switch-to-totp text-lightPrimary dark:text-white hover:underline cursor-pointer" @click="modalMode = 'totp'">{{$t('Use TOTP instead')}}</button>
9193
</p>
92-
<p class="af-2fa-multiple-actions text-center text-red-500 text-xs" v-if="sessionsIdsToResolve.length > 1"> You are confirming {{ sessionsIdsToResolve.length }} actions</p>
94+
<p class="af-2fa-multiple-actions text-center text-red-500 text-xs" v-if="sessionsIdsToResolve.length > 1">
95+
{{ $t('You are confirming {count} action | You are confirming {count} actions', sessionsIdsToResolve.length) }}
96+
</p>
9397
</div>
9498
</div>
9599
</template>
@@ -148,7 +152,7 @@
148152
websocket.unsubscribeByPrefix(`/user2fa/`);
149153
websocket.subscribe(`/user2fa/${props.adminUser.pk}`, async (data: {sessionId: string}) => {
150154
if (!allowAddNewSessions) {
151-
alert({message: 'Some process or user tries to add new actions to confirm. Action was blocked', variant: 'warning'});
155+
alert({message: t('Some process or user tries to add new actions to confirm. Action was blocked'), variant: 'warning'});
152156
return;
153157
}
154158
sessionsIdsToResolve.value.push(data.sessionId);
@@ -160,7 +164,7 @@
160164
isAwaiting2FAResult.value = true;
161165
confirmationResult = await window.adminforthTwoFaModal.get2FaConfirmationResult();
162166
} catch (error) {
163-
console.error('Error during 2FA confirmation:', error);
167+
console.error(t('Error during 2FA confirmation:', error));
164168
}
165169
isAwaiting2FAResult.value = false;
166170
try {
@@ -170,15 +174,15 @@
170174
body: { confirmationResult, sessionsIds: sessionsIdsToResolve.value }
171175
});
172176
if (!response.ok && response.error === 'No session ID or confirmation result'){
173-
alert({message: 'Verification session finished or cancelled.', variant: 'warning'});
177+
alert({message: t('Verification session finished or cancelled.'), variant: 'warning'});
174178
} else if (!response.ok) {
175179
alert({message: response.error || t('Verification failed'), variant: 'danger'});
176180
} else if (response.ok) {
177-
alert({message: 'Verification successful', variant: 'success'});
181+
alert({message: t('Verification successful'), variant: 'success'});
178182
}
179183
sessionsIdsToResolve.value = [];
180184
} catch (error) {
181-
console.error('Error resolving automatic 2FA verification:', error);
185+
console.error(t('Error resolving automatic 2FA verification:', error));
182186
}
183187
allowAddNewSessions = true;
184188
});
@@ -226,7 +230,7 @@
226230
window.adminforthTwoFaModal = {
227231
get2FaConfirmationResult: (title?: string, verifyingCallback?: (confirmationResult: string) => Promise<boolean>) =>
228232
new Promise(async (resolve, reject) => {
229-
if (modelShow.value) throw new Error('Modal is already open');
233+
if (modelShow.value) throw new Error(t('Modal is already open'));
230234
const skipAllowModal = await checkIfSkipAllowModal();
231235
if (skipAllowModal) {
232236
resolve({ code: "123456" }); // dummy code
@@ -303,12 +307,12 @@
303307
}
304308
305309
async function sendConfirmationResult(value: string) {
306-
if (!resolveFn) throw new Error('Modal is not initialized properly');
310+
if (!resolveFn) throw new Error(t('Modal is not initialized properly'));
307311
if (verifyFn) {
308312
try {
309313
const ok = await verifyFn(value);
310314
if (!ok) {
311-
rejectFn?.(new Error('Invalid code'));
315+
rejectFn?.(new Error(t('Invalid code')));
312316
return;
313317
}
314318
} catch (err) {
@@ -393,7 +397,7 @@
393397
}
394398
}
395399
} catch (error) {
396-
console.error('Error checking passkeys:', error);
400+
console.error(t('Error checking passkeys:', error));
397401
// Fallback to TOTP if there's an error
398402
doesUserHavePasskeys.value = false;
399403
modalMode.value = "totp";
@@ -455,7 +459,7 @@
455459
return false;
456460
}
457461
} catch (error) {
458-
console.error('Error checking skip allow modal:', error);
462+
console.error(t('Error checking skip allow modal:', error));
459463
return false;
460464
}
461465
}

custom/TwoFactorsConfirmation.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@
299299
}
300300
});
301301
} catch (error) {
302-
console.error('Error checking if user has passkeys:', error);
302+
console.error(t('Error checking if user has passkeys:', error));
303303
}
304304
}
305305
@@ -318,7 +318,7 @@
318318
try {
319319
options = PublicKeyCredential.parseRequestOptionsFromJSON(_options);
320320
} catch (e) {
321-
console.error('Error parsing request options:', e);
321+
console.error(t('Error parsing request options:', e));
322322
adminforth.alert({message: t('Error initiating passkey authentication.'), variant: 'warning'});
323323
return;
324324
}
@@ -345,14 +345,14 @@
345345
method: 'POST',
346346
});
347347
} catch (error) {
348-
console.error('Error creating sign-in request:', error);
348+
console.error(t('Error creating sign-in request:', error));
349349
return;
350350
}
351351
if (response.ok === true) {
352352
return { _options: response.data, challengeId: response.challengeId };
353353
} else {
354354
adminforth.alert({message: t('Error creating sign-in request.'), variant: 'warning'});
355-
codeError.value = 'Error creating sign-in request.';
355+
codeError.value = t('Error creating sign-in request.');
356356
}
357357
}
358358
@@ -378,7 +378,7 @@
378378
});
379379
return credential;
380380
} catch (error) {
381-
console.error('Error during authentication:', error);
381+
console.error(t('Error during authentication:', error));
382382
// Handle specific concurrent/pending request error cases gracefully
383383
const name = (error && (error.name || error.constructor?.name)) || '';
384384
const message = (error && error.message) || '';

custom/TwoFactorsPasskeysSettings.vue

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="af-passkeys flex flex-col justify-center mr-6 md:mr-12">
33
<h2 class="af-passkeys-title flex items-start justify-start leading-none text-gray-800 dark:text-gray-50 text-3xl font-semibold">{{$t('Passkeys')}}</h2>
4-
<p class="af-passkeys-subtitle text-sm mt-3">Manage your passwordless authentication methods</p>
4+
<p class="af-passkeys-subtitle text-sm mt-3"> {{$t('Manage your passwordless authentication methods')}} </p>
55

66
<div class="af-passkeys-grid mt-6 flex flex-wrap gap-4">
77
<div
@@ -177,13 +177,13 @@
177177
isFetchingPasskey.value = true;
178178
try {
179179
const confirmationResult = await window.adminforthTwoFaModal
180-
.get2FaConfirmationResult('To add passkey first verify yourself');
180+
.get2FaConfirmationResult(t('To add passkey first verify yourself'));
181181
182182
if (!confirmationResult) return;
183183
184184
const { options, error } = await requestPasskeyChallenge(confirmationResult);
185185
if (!options) {
186-
adminforth.alert({ message: error ?? 'Verification failed.', variant: 'warning' });
186+
adminforth.alert({ message: error ?? t('Verification failed.'), variant: 'warning' });
187187
return;
188188
}
189189
@@ -210,9 +210,9 @@
210210
passkeys.value = response.data;
211211
authenticatorAttachment.value = response.authenticatorAttachment;
212212
} catch (error) {
213-
console.error('Error fetching passkeys:', error);
213+
console.error(t('Error fetching passkeys:'), error);
214214
if (coreStore.adminUser?.username) {
215-
adminforth.alert({ message: 'Error fetching passkeys.', variant: 'warning' });
215+
adminforth.alert({ message: t('Error fetching passkeys.'), variant: 'warning' });
216216
}
217217
}
218218
}
@@ -226,12 +226,12 @@
226226
method: 'POST',
227227
body: { mode: addPasskeyMode.value, confirmationResult },
228228
});
229-
if (!response.ok) return { error: response.error ?? 'Verification failed' };
229+
if (!response.ok) return { error: response.error ?? t('Verification failed') };
230230
const options = PublicKeyCredential.parseCreationOptionsFromJSON(response.data);
231231
return { options, challengeId: response.challengeId };
232232
} catch (error) {
233-
console.error('Error requesting passkey challenge:', error);
234-
return { error: 'Failed to request passkey challenge' };
233+
console.error(t('Error requesting passkey challenge:', error));
234+
return { error: t('Failed to request passkey challenge' )};
235235
}
236236
}
237237
@@ -240,8 +240,8 @@
240240
const credential = await navigator.credentials.create({ publicKey: options });
241241
return JSON.stringify((credential as PublicKeyCredential).toJSON());
242242
} catch (error) {
243-
console.error('Error creating WebAuthn credential:', error);
244-
adminforth.alert({ message: 'Error creating passkey.', variant: 'warning' });
243+
console.error(t('Error creating WebAuthn credential:', error));
244+
adminforth.alert({ message: t('Error creating passkey.'), variant: 'warning' });
245245
return null;
246246
}
247247
}
@@ -254,13 +254,13 @@
254254
body: { credential, origin: window.location.origin },
255255
});
256256
if (res.ok) {
257-
adminforth.alert({ message: 'Passkey registered successfully!', variant: 'success' });
257+
adminforth.alert({ message: t('Passkey registered successfully!'), variant: 'success' });
258258
getPasskeys();
259259
} else {
260-
adminforth.alert({ message: 'Error registering passkey.', variant: 'warning' });
260+
adminforth.alert({ message: t('Error registering passkey.'), variant: 'warning' });
261261
}
262262
} catch (error) {
263-
console.error('Error registering passkey:', error);
263+
console.error(t('Error registering passkey:', error));
264264
}
265265
}
266266
@@ -283,15 +283,15 @@
283283
body: { passkeyId },
284284
});
285285
if (response.ok) {
286-
adminforth.alert({ message: 'Passkey deleted successfully!', variant: 'success' });
286+
adminforth.alert({ message: t('Passkey deleted successfully!'), variant: 'success' });
287287
getPasskeys();
288288
} else {
289-
console.error('Error deleting passkey:', response?.error);
290-
adminforth.alert({ message: 'Error deleting passkey.', variant: 'warning' });
289+
console.error(t('Error deleting passkey:', response?.error));
290+
adminforth.alert({ message: t('Error deleting passkey.'), variant: 'warning' });
291291
}
292292
} catch (error) {
293-
console.error('Error deleting passkey:', error);
294-
adminforth.alert({ message: 'Error deleting passkey.', variant: 'warning' });
293+
console.error(t('Error deleting passkey:', error));
294+
adminforth.alert({ message: t('Error deleting passkey.'), variant: 'warning' });
295295
}
296296
}
297297
@@ -303,15 +303,15 @@
303303
body: { passkeyId, newName: name },
304304
});
305305
if (response.ok) {
306-
adminforth.alert({ message: 'Passkey updated successfully!', variant: 'success' });
306+
adminforth.alert({ message: t('Passkey updated successfully!'), variant: 'success' });
307307
getPasskeys();
308308
} else {
309-
console.error('Error updating passkey:', response.error);
310-
adminforth.alert({ message: 'Error updating passkey.', variant: 'warning' });
309+
console.error(t('Error updating passkey:', response.error));
310+
adminforth.alert({ message: t('Error updating passkey.'), variant: 'warning' });
311311
}
312312
} catch (error) {
313-
console.error('Error updating passkey:', error);
314-
adminforth.alert({ message: 'Error updating passkey.', variant: 'warning' });
313+
console.error(t('Error updating passkey:', error));
314+
adminforth.alert({ message: t('Error updating passkey.'), variant: 'warning' });
315315
}
316316
}
317317

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
"node-2fa": "^2.0.3"
2929
},
3030
"peerDependencies": {
31-
"adminforth": "^2.50.0"
31+
"adminforth": "^2.50.1"
3232
},
3333
"devDependencies": {
3434
"@types/node": "^22.10.7",
35-
"adminforth": "^2.50.0",
35+
"adminforth": "^2.50.1",
3636
"semantic-release": "^24.2.1",
3737
"semantic-release-slack-bot": "^4.0.2",
3838
"typescript": "^5.7.3"

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)