jwtbutler 1.9.7 → 1.9.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.
package/README.md CHANGED
@@ -58,7 +58,8 @@ now instantiate the object with the basic configuration:
58
58
  ```js
59
59
  const api = new jwtbutler({
60
60
  auth_server: 'https://example-auth-server.vielhuber.dev/auth',
61
- auth_login: 'email'
61
+ auth_login: 'email',
62
+ language: 'en'
62
63
  });
63
64
  ```
64
65
 
@@ -32,6 +32,9 @@ class jwtbutler {
32
32
  if (!('passkeys' in config)) {
33
33
  config.passkeys = false;
34
34
  }
35
+ if (!('language' in config)) {
36
+ config.language = 'en';
37
+ }
35
38
  this.config = config;
36
39
  }
37
40
  isLoggedIn() {
@@ -475,6 +478,60 @@ class jwtbutler {
475
478
  passkeyEnabled() {
476
479
  return this.config.passkeys !== false;
477
480
  }
481
+ responseMessage(response) {
482
+ let messages = {
483
+ en: {
484
+ _default: 'Not successful',
485
+ 'unknown route': 'Unknown route!',
486
+ 'captcha not successful': 'Captcha not successful',
487
+ 'too many login attempts': 'Too many login attempts. Please try again later.',
488
+ 'auth successful': 'Successfully logged in',
489
+ 'auth not successful': 'Not successful',
490
+ 'invalid token': 'Invalid token',
491
+ 'logout successful': 'Successfully logged out',
492
+ 'logout not successful': 'Logout not successful',
493
+ 'valid token': 'Valid token',
494
+ 'passkey registration options created': 'Passkey registration prepared',
495
+ 'passkey registration options not created': 'Passkey registration not prepared',
496
+ 'passkey registered': 'Passkey registered',
497
+ 'passkey not registered': 'Passkey not registered',
498
+ 'passkey login options created': 'Passkey login prepared',
499
+ 'passkey login options not created': 'Passkey login not prepared',
500
+ 'passkey auth not successful': 'Passkey not successful',
501
+ 'passkey deleted': 'Passkey deleted',
502
+ 'passkey not deleted': 'Passkey not deleted'
503
+ },
504
+ de: {
505
+ _default: 'Nicht erfolgreich',
506
+ 'unknown route': 'Unbekannte Route!',
507
+ 'captcha not successful': 'Captcha nicht erfolgreich',
508
+ 'too many login attempts': 'Zu viele Loginversuche. Bitte später erneut versuchen.',
509
+ 'auth successful': 'Erfolgreich eingeloggt',
510
+ 'auth not successful': 'Nicht erfolgreich',
511
+ 'invalid token': 'Falsches Token',
512
+ 'logout successful': 'Erfolgreich ausgeloggt',
513
+ 'logout not successful': 'Nicht erfolgreich ausgeloggt',
514
+ 'valid token': 'Korrektes Token',
515
+ 'passkey registration options created': 'Passkey-Registrierung vorbereitet',
516
+ 'passkey registration options not created': 'Passkey-Registrierung nicht vorbereitet',
517
+ 'passkey registered': 'Passkey registriert',
518
+ 'passkey not registered': 'Passkey nicht registriert',
519
+ 'passkey login options created': 'Passkey-Login vorbereitet',
520
+ 'passkey login options not created': 'Passkey-Login nicht vorbereitet',
521
+ 'passkey auth not successful': 'Passkey nicht erfolgreich',
522
+ 'passkey deleted': 'Passkey gelöscht',
523
+ 'passkey not deleted': 'Passkey nicht gelöscht'
524
+ }
525
+ };
526
+ let language = this.config.language in messages ? this.config.language : 'en';
527
+ if (response !== undefined && response !== null && 'message' in response && response.message in messages[language]) {
528
+ return messages[language][response.message];
529
+ }
530
+ if (response !== undefined && response !== null && 'public_message' in response) {
531
+ return response.public_message;
532
+ }
533
+ return messages[language]._default;
534
+ }
478
535
  captchaRender() {
479
536
  return new Promise((resolve, reject) => {
480
537
  if (!this.captchaEnabled()) {
@@ -491,10 +548,14 @@ class jwtbutler {
491
548
  resolve();
492
549
  return;
493
550
  }
494
- captcha.setAttribute('data-widget-id', window.hcaptcha.render(captcha, {
551
+ let options = {
495
552
  sitekey: this.config.captcha.sitekey,
496
553
  theme: this.config.captcha.theme || 'light'
497
- }));
554
+ };
555
+ if (this.config.language !== '') {
556
+ options.hl = this.config.language;
557
+ }
558
+ captcha.setAttribute('data-widget-id', window.hcaptcha.render(captcha, options));
498
559
  resolve();
499
560
  }).catch(error => {
500
561
  reject(error);
@@ -531,14 +592,16 @@ class jwtbutler {
531
592
  let captcha = form.querySelector('.' + this.config.login_form_class + '__captcha');
532
593
  if (captcha === null || !('hcaptcha' in window)) {
533
594
  reject({
534
- public_message: 'Captcha nicht erfolgreich'
595
+ message: 'captcha not successful',
596
+ public_message: 'Captcha not successful'
535
597
  });
536
598
  return;
537
599
  }
538
600
  let token = window.hcaptcha.getResponse(captcha.getAttribute('data-widget-id'));
539
601
  if (token === '') {
540
602
  reject({
541
- public_message: 'Captcha nicht erfolgreich'
603
+ message: 'captcha not successful',
604
+ public_message: 'Captcha not successful'
542
605
  });
543
606
  return;
544
607
  }
@@ -596,7 +659,7 @@ class jwtbutler {
596
659
  } else {
597
660
  this.removeLoadingStates();
598
661
  this.captchaReset(form);
599
- form.insertAdjacentHTML('afterbegin', '<div class="' + this.config.login_form_class + '__error">' + (response !== undefined && response !== null && 'public_message' in response ? response.public_message : 'Nicht erfolgreich') + '</div>');
662
+ form.insertAdjacentHTML('afterbegin', '<div class="' + this.config.login_form_class + '__error">' + this.responseMessage(response) + '</div>');
600
663
  }
601
664
  });
602
665
  e.preventDefault();
@@ -615,7 +678,7 @@ class jwtbutler {
615
678
  resolve();
616
679
  }).catch(response => {
617
680
  this.removeLoadingStates();
618
- form.insertAdjacentHTML('afterbegin', '<div class="' + this.config.login_form_class + '__error">' + (response !== undefined && response !== null && 'public_message' in response ? response.public_message : 'Nicht erfolgreich') + '</div>');
681
+ form.insertAdjacentHTML('afterbegin', '<div class="' + this.config.login_form_class + '__error">' + this.responseMessage(response) + '</div>');
619
682
  });
620
683
  e.preventDefault();
621
684
  }, false);
package/package.json CHANGED
@@ -81,7 +81,7 @@
81
81
  "jest-environment-node": "30.4.1"
82
82
  },
83
83
  "name": "jwtbutler",
84
- "version": "1.9.7",
84
+ "version": "1.9.9",
85
85
  "description": "",
86
86
  "main": "_js/_build/script.js",
87
87
  "files": [