@micha.bigler/ui-core-micha 1.4.19 → 1.4.22
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/dist/auth/AuthContext.js +0 -1
- package/dist/auth/authApi.js +137 -378
- package/dist/components/MFAComponent.js +7 -7
- package/dist/components/MfaLoginComponent.js +6 -5
- package/dist/components/PasskeysComponent.js +5 -5
- package/dist/components/SecurityComponent.js +4 -3
- package/dist/components/SupportRecoveryRequestsTab.js +5 -5
- package/dist/components/UserInviteComponent.js +38 -0
- package/dist/components/UserListComponent.js +83 -0
- package/dist/i18n/authTranslations.js +25 -0
- package/dist/pages/AccountPage.js +67 -23
- package/dist/pages/LoginPage.js +6 -5
- package/dist/pages/PasswordInvitePage.js +3 -3
- package/dist/pages/SignUpPage.js +3 -3
- package/dist/utils/authService.js +53 -0
- package/dist/utils/errors.js +33 -0
- package/dist/utils/webauthn.js +44 -0
- package/package.json +1 -1
- package/src/auth/AuthContext.jsx +0 -1
- package/src/auth/authApi.jsx +143 -478
- package/src/components/MFAComponent.jsx +7 -7
- package/src/components/MfaLoginComponent.jsx +6 -5
- package/src/components/PasskeysComponent.jsx +5 -5
- package/src/components/SecurityComponent.jsx +4 -3
- package/src/components/SupportRecoveryRequestsTab.jsx +7 -5
- package/src/components/UserInviteComponent.jsx +69 -0
- package/src/components/UserListComponent.jsx +167 -0
- package/src/i18n/authTranslations.js +25 -0
- package/src/pages/AccountPage.jsx +140 -47
- package/src/pages/LoginPage.jsx +6 -5
- package/src/pages/PasswordInvitePage.jsx +3 -3
- package/src/pages/SignUpPage.jsx +3 -3
- package/src/utils/authService.js +68 -0
- package/src/utils/errors.js +39 -0
- package/src/utils/webauthn.js +51 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/utils/errors.js
|
|
2
|
+
export function extractErrorInfo(error) {
|
|
3
|
+
var _a, _b, _c, _d;
|
|
4
|
+
const status = (_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : null;
|
|
5
|
+
const data = (_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) !== null && _d !== void 0 ? _d : null;
|
|
6
|
+
if (!data) {
|
|
7
|
+
return { status, code: null, message: error.message || null, raw: null };
|
|
8
|
+
}
|
|
9
|
+
// Allauth Headless structure often nests errors in "errors" array or "status" key
|
|
10
|
+
if (Array.isArray(data.errors) && data.errors.length > 0) {
|
|
11
|
+
// Pick the first error code
|
|
12
|
+
const first = data.errors[0];
|
|
13
|
+
return { status, code: first.code, message: first.message, raw: data };
|
|
14
|
+
}
|
|
15
|
+
if (typeof data.code === 'string') {
|
|
16
|
+
return { status, code: data.code, message: null, raw: data };
|
|
17
|
+
}
|
|
18
|
+
// Fallback for generic Django errors
|
|
19
|
+
if (typeof data.detail === 'string') {
|
|
20
|
+
return { status, code: 'GENERIC', message: data.detail, raw: data };
|
|
21
|
+
}
|
|
22
|
+
return { status, code: null, message: null, raw: data };
|
|
23
|
+
}
|
|
24
|
+
export function normaliseApiError(error, defaultCode = 'Auth.GENERIC_ERROR') {
|
|
25
|
+
const info = extractErrorInfo(error);
|
|
26
|
+
const code = info.code || defaultCode;
|
|
27
|
+
const message = info.message || code || defaultCode;
|
|
28
|
+
const err = new Error(message);
|
|
29
|
+
err.code = code;
|
|
30
|
+
err.status = info.status;
|
|
31
|
+
err.raw = info.raw;
|
|
32
|
+
return err;
|
|
33
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/utils/webauthn.js
|
|
2
|
+
export function bufferToBase64URL(buffer) {
|
|
3
|
+
const bytes = new Uint8Array(buffer);
|
|
4
|
+
let str = '';
|
|
5
|
+
for (const char of bytes) {
|
|
6
|
+
str += String.fromCharCode(char);
|
|
7
|
+
}
|
|
8
|
+
const base64 = btoa(str);
|
|
9
|
+
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
10
|
+
}
|
|
11
|
+
export function serializeCredential(credential) {
|
|
12
|
+
const p = {
|
|
13
|
+
id: credential.id,
|
|
14
|
+
rawId: bufferToBase64URL(credential.rawId),
|
|
15
|
+
type: credential.type,
|
|
16
|
+
response: {
|
|
17
|
+
clientDataJSON: bufferToBase64URL(credential.response.clientDataJSON),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
if (credential.response.attestationObject) {
|
|
21
|
+
p.response.attestationObject = bufferToBase64URL(credential.response.attestationObject);
|
|
22
|
+
}
|
|
23
|
+
if (credential.response.authenticatorData) {
|
|
24
|
+
p.response.authenticatorData = bufferToBase64URL(credential.response.authenticatorData);
|
|
25
|
+
}
|
|
26
|
+
if (credential.response.signature) {
|
|
27
|
+
p.response.signature = bufferToBase64URL(credential.response.signature);
|
|
28
|
+
}
|
|
29
|
+
if (credential.response.userHandle) {
|
|
30
|
+
p.response.userHandle = bufferToBase64URL(credential.response.userHandle);
|
|
31
|
+
}
|
|
32
|
+
if (typeof credential.getClientExtensionResults === 'function') {
|
|
33
|
+
p.clientExtensionResults = credential.getClientExtensionResults();
|
|
34
|
+
}
|
|
35
|
+
return p;
|
|
36
|
+
}
|
|
37
|
+
export function ensureWebAuthnSupport() {
|
|
38
|
+
if (typeof window === 'undefined' ||
|
|
39
|
+
typeof navigator === 'undefined' ||
|
|
40
|
+
!window.PublicKeyCredential ||
|
|
41
|
+
!navigator.credentials) {
|
|
42
|
+
throw new Error('Auth.PASSKEY_NOT_SUPPORTED');
|
|
43
|
+
}
|
|
44
|
+
}
|
package/package.json
CHANGED