jwtbutler 1.9.8 → 2.0.0
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 +3 -3
- package/_js/_build/script.js +65 -6
- package/package.json +1 -1
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
|
|
|
@@ -71,8 +72,7 @@ const api = new jwtbutler({
|
|
|
71
72
|
captcha: {
|
|
72
73
|
provider: 'hcaptcha',
|
|
73
74
|
sitekey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
74
|
-
theme: 'light'
|
|
75
|
-
language: 'en'
|
|
75
|
+
theme: 'light'
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
```
|
package/_js/_build/script.js
CHANGED
|
@@ -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()) {
|
|
@@ -495,8 +552,8 @@ class jwtbutler {
|
|
|
495
552
|
sitekey: this.config.captcha.sitekey,
|
|
496
553
|
theme: this.config.captcha.theme || 'light'
|
|
497
554
|
};
|
|
498
|
-
if (
|
|
499
|
-
options.hl = this.config.
|
|
555
|
+
if (this.config.language !== '') {
|
|
556
|
+
options.hl = this.config.language;
|
|
500
557
|
}
|
|
501
558
|
captcha.setAttribute('data-widget-id', window.hcaptcha.render(captcha, options));
|
|
502
559
|
resolve();
|
|
@@ -535,14 +592,16 @@ class jwtbutler {
|
|
|
535
592
|
let captcha = form.querySelector('.' + this.config.login_form_class + '__captcha');
|
|
536
593
|
if (captcha === null || !('hcaptcha' in window)) {
|
|
537
594
|
reject({
|
|
538
|
-
|
|
595
|
+
message: 'captcha not successful',
|
|
596
|
+
public_message: 'Captcha not successful'
|
|
539
597
|
});
|
|
540
598
|
return;
|
|
541
599
|
}
|
|
542
600
|
let token = window.hcaptcha.getResponse(captcha.getAttribute('data-widget-id'));
|
|
543
601
|
if (token === '') {
|
|
544
602
|
reject({
|
|
545
|
-
|
|
603
|
+
message: 'captcha not successful',
|
|
604
|
+
public_message: 'Captcha not successful'
|
|
546
605
|
});
|
|
547
606
|
return;
|
|
548
607
|
}
|
|
@@ -600,7 +659,7 @@ class jwtbutler {
|
|
|
600
659
|
} else {
|
|
601
660
|
this.removeLoadingStates();
|
|
602
661
|
this.captchaReset(form);
|
|
603
|
-
form.insertAdjacentHTML('afterbegin', '<div class="' + this.config.login_form_class + '__error">' + (response
|
|
662
|
+
form.insertAdjacentHTML('afterbegin', '<div class="' + this.config.login_form_class + '__error">' + this.responseMessage(response) + '</div>');
|
|
604
663
|
}
|
|
605
664
|
});
|
|
606
665
|
e.preventDefault();
|
|
@@ -619,7 +678,7 @@ class jwtbutler {
|
|
|
619
678
|
resolve();
|
|
620
679
|
}).catch(response => {
|
|
621
680
|
this.removeLoadingStates();
|
|
622
|
-
form.insertAdjacentHTML('afterbegin', '<div class="' + this.config.login_form_class + '__error">' + (response
|
|
681
|
+
form.insertAdjacentHTML('afterbegin', '<div class="' + this.config.login_form_class + '__error">' + this.responseMessage(response) + '</div>');
|
|
623
682
|
});
|
|
624
683
|
e.preventDefault();
|
|
625
684
|
}, false);
|