@alore/auth-react-sdk 1.1.0-alpha.6 → 1.1.0-alpha.8
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/types.d.ts +0 -3
- package/dist/utils/AloreAuth.d.ts +8 -28
- package/dist/utils/AloreAuth.js +63 -101
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -20,7 +20,6 @@ export type KeyDerivationFunction = 'argon2d' | 'pbkdf2';
|
|
|
20
20
|
* @property logoUrl - Optional string for logo URL.
|
|
21
21
|
* @property socialProviders - Optional social login providers.
|
|
22
22
|
* @property enableWalletCreation - Optional boolean to enable wallet creation.
|
|
23
|
-
* @property allowedEmailDomains - Optional allowed email domain(s). If provided, authentication will only allow emails from these domains. Accepts a single string (e.g., 'bealore.com' or '@bealore.com') or an array of strings.
|
|
24
23
|
*/
|
|
25
24
|
export interface AuthProviderConfig {
|
|
26
25
|
rpDomain?: string;
|
|
@@ -38,14 +37,12 @@ export interface AuthProviderConfig {
|
|
|
38
37
|
socialProviders?: SocialProvider[];
|
|
39
38
|
enableWalletCreation?: boolean;
|
|
40
39
|
firebaseCompatible?: boolean;
|
|
41
|
-
allowedEmailDomains?: string | string[];
|
|
42
40
|
}
|
|
43
41
|
export interface AuthMachineContext {
|
|
44
42
|
authProviderConfigs?: AuthProviderConfig;
|
|
45
43
|
salt?: string;
|
|
46
44
|
error?: string;
|
|
47
45
|
active2fa?: TwoFactorAuth[];
|
|
48
|
-
sessionId?: string;
|
|
49
46
|
registerUser?: {
|
|
50
47
|
email: string;
|
|
51
48
|
nickname: string;
|
|
@@ -5,7 +5,6 @@ export declare class AloreAuth {
|
|
|
5
5
|
protected readonly clientId: string;
|
|
6
6
|
constructor(clientId: string, aloreBaseUrl?: string, config?: AuthProviderConfig);
|
|
7
7
|
services: {
|
|
8
|
-
isEmailAllowed: (context: AuthMachineContext, email?: string | null) => boolean;
|
|
9
8
|
healthCheck: () => Promise<{
|
|
10
9
|
data: boolean;
|
|
11
10
|
}>;
|
|
@@ -16,17 +15,13 @@ export declare class AloreAuth {
|
|
|
16
15
|
};
|
|
17
16
|
}) => Promise<{
|
|
18
17
|
salt: string;
|
|
19
|
-
|
|
20
|
-
} | {
|
|
21
|
-
error: string;
|
|
22
|
-
salt?: undefined;
|
|
23
|
-
}>;
|
|
18
|
+
} | undefined>;
|
|
24
19
|
verifyEmail: (context: AuthMachineContext, event: {
|
|
25
20
|
type: 'VERIFY_EMAIL';
|
|
26
21
|
payload: {
|
|
27
22
|
secureCode: string;
|
|
28
23
|
};
|
|
29
|
-
}) => Promise<{}>;
|
|
24
|
+
}) => Promise<{} | undefined>;
|
|
30
25
|
completeRegistration: (context: AuthMachineContext, event: {
|
|
31
26
|
type: 'COMPLETE_REGISTRATION';
|
|
32
27
|
payload: {
|
|
@@ -42,11 +37,7 @@ export declare class AloreAuth {
|
|
|
42
37
|
email: string;
|
|
43
38
|
passwordHash: string;
|
|
44
39
|
};
|
|
45
|
-
}) => Promise<{
|
|
46
|
-
error?: undefined;
|
|
47
|
-
} | {
|
|
48
|
-
error: string;
|
|
49
|
-
}>;
|
|
40
|
+
}) => Promise<{}>;
|
|
50
41
|
sendConfirmationEmail: (context: AuthMachineContext, event: {
|
|
51
42
|
type: 'RESEND_CODE';
|
|
52
43
|
payload: {
|
|
@@ -67,23 +58,13 @@ export declare class AloreAuth {
|
|
|
67
58
|
};
|
|
68
59
|
}) => Promise<{
|
|
69
60
|
salt: any;
|
|
70
|
-
|
|
71
|
-
error?: undefined;
|
|
72
|
-
} | {
|
|
73
|
-
error: string;
|
|
74
|
-
salt?: undefined;
|
|
75
|
-
sessionId?: undefined;
|
|
76
|
-
}>;
|
|
61
|
+
} | undefined>;
|
|
77
62
|
sendCode: (context: AuthMachineContext, event: {
|
|
78
63
|
type: 'SEND_CODE';
|
|
79
64
|
payload: {
|
|
80
65
|
email: string;
|
|
81
66
|
};
|
|
82
|
-
}) => Promise<{
|
|
83
|
-
error: string;
|
|
84
|
-
} | {
|
|
85
|
-
error?: undefined;
|
|
86
|
-
}>;
|
|
67
|
+
}) => Promise<{}>;
|
|
87
68
|
verifyLogin: (context: AuthMachineContext, event: {
|
|
88
69
|
type: 'VERIFY_LOGIN';
|
|
89
70
|
payload: {
|
|
@@ -103,7 +84,7 @@ export declare class AloreAuth {
|
|
|
103
84
|
isForgeClaim?: boolean | undefined;
|
|
104
85
|
locale?: string | undefined;
|
|
105
86
|
};
|
|
106
|
-
}) => Promise<
|
|
87
|
+
}) => Promise<{}>;
|
|
107
88
|
startRegisterPasskey: (context: AuthMachineContext, event: {
|
|
108
89
|
type: 'START_PASSKEY_REGISTER';
|
|
109
90
|
payload: {
|
|
@@ -232,7 +213,6 @@ export declare class AloreAuth {
|
|
|
232
213
|
nickname: any;
|
|
233
214
|
salt: any;
|
|
234
215
|
};
|
|
235
|
-
sessionId: any;
|
|
236
216
|
isNewUser?: undefined;
|
|
237
217
|
socialProviderRegisterUser?: undefined;
|
|
238
218
|
} | {
|
|
@@ -245,12 +225,10 @@ export declare class AloreAuth {
|
|
|
245
225
|
googleOtpCode?: undefined;
|
|
246
226
|
salt?: undefined;
|
|
247
227
|
googleUser?: undefined;
|
|
248
|
-
sessionId?: undefined;
|
|
249
228
|
} | {
|
|
250
229
|
googleOtpCode?: undefined;
|
|
251
230
|
salt?: undefined;
|
|
252
231
|
googleUser?: undefined;
|
|
253
|
-
sessionId?: undefined;
|
|
254
232
|
isNewUser?: undefined;
|
|
255
233
|
socialProviderRegisterUser?: undefined;
|
|
256
234
|
}>;
|
|
@@ -265,6 +243,8 @@ export declare class AloreAuth {
|
|
|
265
243
|
};
|
|
266
244
|
private delay;
|
|
267
245
|
fetchWithProgressiveBackoff(url: RequestInfo | URL, options?: RequestInit, config?: FetchWithProgressiveBackoffConfig): Promise<Response>;
|
|
246
|
+
private parseErrorResponse;
|
|
247
|
+
private throwParsedResponseError;
|
|
268
248
|
private verifyBackendStatus;
|
|
269
249
|
private extractErrorInfo;
|
|
270
250
|
}
|
package/dist/utils/AloreAuth.js
CHANGED
|
@@ -13,28 +13,6 @@ const DEFAULT_URL = 'https://alpha-api.bealore.com/v1';
|
|
|
13
13
|
export class AloreAuth {
|
|
14
14
|
constructor(clientId, aloreBaseUrl, config) {
|
|
15
15
|
this.services = {
|
|
16
|
-
// Utility to check if an email is allowed based on allowedEmailDomains config
|
|
17
|
-
isEmailAllowed: (context, email) => {
|
|
18
|
-
var _a;
|
|
19
|
-
const allowedConf = (_a = context.authProviderConfigs) === null || _a === void 0 ? void 0 : _a.allowedEmailDomains;
|
|
20
|
-
const allowedList =
|
|
21
|
-
// eslint-disable-next-line no-nested-ternary
|
|
22
|
-
typeof allowedConf === 'string'
|
|
23
|
-
? [allowedConf]
|
|
24
|
-
: Array.isArray(allowedConf)
|
|
25
|
-
? allowedConf
|
|
26
|
-
: [];
|
|
27
|
-
if (allowedList.length === 0)
|
|
28
|
-
return true;
|
|
29
|
-
if (!email)
|
|
30
|
-
return false;
|
|
31
|
-
const domain = (email.split('@')[1] || '').toLowerCase();
|
|
32
|
-
// Allow items like '@bealore.com' or 'bealore.com'
|
|
33
|
-
return allowedList.some((d) => {
|
|
34
|
-
const normalized = d.startsWith('@') ? d.slice(1) : d;
|
|
35
|
-
return domain === normalized.toLowerCase();
|
|
36
|
-
});
|
|
37
|
-
},
|
|
38
16
|
healthCheck: () => __awaiter(this, void 0, void 0, function* () {
|
|
39
17
|
try {
|
|
40
18
|
yield this.verifyBackendStatus();
|
|
@@ -47,9 +25,6 @@ export class AloreAuth {
|
|
|
47
25
|
// Email and password flow
|
|
48
26
|
retrieveSalt: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
49
27
|
const { email } = event.payload;
|
|
50
|
-
if (!this.services.isEmailAllowed(context, email)) {
|
|
51
|
-
throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
|
|
52
|
-
}
|
|
53
28
|
const { credentialEmail } = context;
|
|
54
29
|
const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/salt/${email || credentialEmail}`, {
|
|
55
30
|
headers: {
|
|
@@ -60,7 +35,8 @@ export class AloreAuth {
|
|
|
60
35
|
const salt = yield response.json();
|
|
61
36
|
return { salt };
|
|
62
37
|
}
|
|
63
|
-
|
|
38
|
+
// Propagate parsed error so machine receives full payload as event.data
|
|
39
|
+
yield this.throwParsedResponseError(response);
|
|
64
40
|
}),
|
|
65
41
|
verifyEmail: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
66
42
|
const { secureCode } = event.payload;
|
|
@@ -71,20 +47,15 @@ export class AloreAuth {
|
|
|
71
47
|
},
|
|
72
48
|
body: JSON.stringify({
|
|
73
49
|
emailCode: secureCode,
|
|
74
|
-
sessionId: context.sessionId,
|
|
75
50
|
}),
|
|
76
51
|
});
|
|
77
52
|
if (response.ok) {
|
|
78
53
|
return {};
|
|
79
54
|
}
|
|
80
|
-
|
|
81
|
-
throw new Error((data === null || data === void 0 ? void 0 : data.message) || (data === null || data === void 0 ? void 0 : data.error) || data);
|
|
55
|
+
yield this.throwParsedResponseError(response);
|
|
82
56
|
}),
|
|
83
57
|
completeRegistration: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
84
58
|
const { email, nickname, passwordHash, device } = event.payload;
|
|
85
|
-
if (!this.services.isEmailAllowed(context, email)) {
|
|
86
|
-
throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
|
|
87
|
-
}
|
|
88
59
|
const { firebaseCompatible } = context.authProviderConfigs || {};
|
|
89
60
|
const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/account-registration${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
|
|
90
61
|
method: 'POST',
|
|
@@ -101,7 +72,7 @@ export class AloreAuth {
|
|
|
101
72
|
const data = yield response.json();
|
|
102
73
|
if (response.ok)
|
|
103
74
|
return data;
|
|
104
|
-
|
|
75
|
+
yield this.throwParsedResponseError(response);
|
|
105
76
|
}),
|
|
106
77
|
confirmPassword: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
107
78
|
const { email, passwordHash } = event.payload;
|
|
@@ -116,14 +87,11 @@ export class AloreAuth {
|
|
|
116
87
|
}),
|
|
117
88
|
});
|
|
118
89
|
if (!response.ok)
|
|
119
|
-
|
|
120
|
-
return {
|
|
90
|
+
yield this.throwParsedResponseError(response);
|
|
91
|
+
return {};
|
|
121
92
|
}),
|
|
122
93
|
sendConfirmationEmail: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
123
94
|
const { email, nickname, locale } = event.payload;
|
|
124
|
-
if (!this.services.isEmailAllowed(context, email)) {
|
|
125
|
-
throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
|
|
126
|
-
}
|
|
127
95
|
const searchParams = new URLSearchParams();
|
|
128
96
|
const url = '/auth/v1/confirmation-email';
|
|
129
97
|
if (locale) {
|
|
@@ -144,20 +112,14 @@ export class AloreAuth {
|
|
|
144
112
|
});
|
|
145
113
|
if (response.ok) {
|
|
146
114
|
const resJson = yield response.json();
|
|
147
|
-
const { salt
|
|
148
|
-
return { salt
|
|
149
|
-
}
|
|
150
|
-
if (response.status === 403) {
|
|
151
|
-
const resJson = yield response.json();
|
|
152
|
-
throw new Error(resJson);
|
|
115
|
+
const { salt } = resJson;
|
|
116
|
+
return { salt };
|
|
153
117
|
}
|
|
154
|
-
|
|
118
|
+
// Throw parsed error for machine to consume
|
|
119
|
+
yield this.throwParsedResponseError(response);
|
|
155
120
|
}),
|
|
156
121
|
sendCode: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
157
122
|
const { email } = event.payload;
|
|
158
|
-
if (!this.services.isEmailAllowed(context, email)) {
|
|
159
|
-
throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
|
|
160
|
-
}
|
|
161
123
|
const response = yield this.fetchWithProgressiveBackoff(`/reset-password`, {
|
|
162
124
|
method: 'POST',
|
|
163
125
|
headers: {
|
|
@@ -168,15 +130,11 @@ export class AloreAuth {
|
|
|
168
130
|
}),
|
|
169
131
|
});
|
|
170
132
|
if (!response.ok)
|
|
171
|
-
|
|
133
|
+
yield this.throwParsedResponseError(response);
|
|
172
134
|
return {};
|
|
173
135
|
}),
|
|
174
136
|
verifyLogin: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
175
|
-
var _a, _b;
|
|
176
137
|
const { email, passwordHash, device, locale } = event.payload;
|
|
177
|
-
if (!this.services.isEmailAllowed(context, email || context.credentialEmail)) {
|
|
178
|
-
throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
|
|
179
|
-
}
|
|
180
138
|
const { credentialEmail } = context;
|
|
181
139
|
const searchParams = new URLSearchParams();
|
|
182
140
|
const url = '/auth/v1/login-verification';
|
|
@@ -197,27 +155,15 @@ export class AloreAuth {
|
|
|
197
155
|
device,
|
|
198
156
|
}),
|
|
199
157
|
});
|
|
200
|
-
const data = yield response.json();
|
|
201
158
|
if (!response.ok) {
|
|
202
|
-
|
|
203
|
-
return { active2fa: data };
|
|
204
|
-
}
|
|
205
|
-
if (((_a = data === null || data === void 0 ? void 0 : data.error) === null || _a === void 0 ? void 0 : _a.includes('2FA')) || ((_b = data === null || data === void 0 ? void 0 : data.error) === null || _b === void 0 ? void 0 : _b.includes('device'))) {
|
|
206
|
-
return { error: data === null || data === void 0 ? void 0 : data.error };
|
|
207
|
-
}
|
|
208
|
-
throw new Error((data === null || data === void 0 ? void 0 : data.message) || (data === null || data === void 0 ? void 0 : data.error) || data);
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
return data;
|
|
159
|
+
yield this.throwParsedResponseError(response);
|
|
212
160
|
}
|
|
161
|
+
return {};
|
|
213
162
|
}),
|
|
214
163
|
// Passkey registration flow
|
|
215
164
|
startRegisterPasskey: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
216
165
|
const { rpDomain } = context.authProviderConfigs || {};
|
|
217
166
|
const { email, nickname, device } = event.payload || context.registerUser;
|
|
218
|
-
if (email && !this.services.isEmailAllowed(context, email)) {
|
|
219
|
-
throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
|
|
220
|
-
}
|
|
221
167
|
const startPasskeyRegistrationResponse = yield this.fetchWithProgressiveBackoff('/auth/v1/account-registration-passkey', {
|
|
222
168
|
method: 'POST',
|
|
223
169
|
headers: {
|
|
@@ -231,14 +177,13 @@ export class AloreAuth {
|
|
|
231
177
|
}),
|
|
232
178
|
});
|
|
233
179
|
const data = yield startPasskeyRegistrationResponse.json();
|
|
180
|
+
if (!startPasskeyRegistrationResponse.ok)
|
|
181
|
+
yield this.throwParsedResponseError(startPasskeyRegistrationResponse);
|
|
234
182
|
return data;
|
|
235
183
|
}),
|
|
236
184
|
finishRegisterPasskey: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
237
185
|
const { rpDomain } = context.authProviderConfigs || {};
|
|
238
186
|
const { email, nickname, device, passkeyRegistration } = event.payload || {};
|
|
239
|
-
if (email && !this.services.isEmailAllowed(context, email)) {
|
|
240
|
-
throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
|
|
241
|
-
}
|
|
242
187
|
const response = yield this.fetchWithProgressiveBackoff('/auth/v1/account-registration-passkey-finish', {
|
|
243
188
|
method: 'POST',
|
|
244
189
|
headers: {
|
|
@@ -249,7 +194,6 @@ export class AloreAuth {
|
|
|
249
194
|
userNickname: nickname || null,
|
|
250
195
|
userDevice: device,
|
|
251
196
|
passkeyRegistration,
|
|
252
|
-
sessionId: context.sessionId,
|
|
253
197
|
rpOrigin: rpDomain,
|
|
254
198
|
}),
|
|
255
199
|
});
|
|
@@ -259,12 +203,9 @@ export class AloreAuth {
|
|
|
259
203
|
}),
|
|
260
204
|
// Passkey login flow
|
|
261
205
|
startPasskeyAuth: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
262
|
-
var
|
|
206
|
+
var _a;
|
|
263
207
|
const { rpDomain } = context.authProviderConfigs || {};
|
|
264
|
-
const email = (
|
|
265
|
-
if (email && !this.services.isEmailAllowed(context, email)) {
|
|
266
|
-
throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
|
|
267
|
-
}
|
|
208
|
+
const email = (_a = event.payload) === null || _a === void 0 ? void 0 : _a.email;
|
|
268
209
|
const searchParams = new URLSearchParams();
|
|
269
210
|
const url = '/auth/v1/login-passkey';
|
|
270
211
|
if (rpDomain) {
|
|
@@ -290,14 +231,13 @@ export class AloreAuth {
|
|
|
290
231
|
},
|
|
291
232
|
body: JSON.stringify({
|
|
292
233
|
passkeyAuth,
|
|
293
|
-
sessionId: context.sessionId,
|
|
294
234
|
rpOrigin: rpDomain,
|
|
295
235
|
}),
|
|
296
236
|
});
|
|
297
237
|
const data = yield response.json();
|
|
298
238
|
if (response.ok)
|
|
299
239
|
return data;
|
|
300
|
-
|
|
240
|
+
yield this.throwParsedResponseError(response);
|
|
301
241
|
}),
|
|
302
242
|
// Hardware 2FA flow
|
|
303
243
|
verify2faCode: (_context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -317,7 +257,7 @@ export class AloreAuth {
|
|
|
317
257
|
const data = yield response.json();
|
|
318
258
|
if (response.ok)
|
|
319
259
|
return data;
|
|
320
|
-
|
|
260
|
+
yield this.throwParsedResponseError(response);
|
|
321
261
|
}),
|
|
322
262
|
authenticateWebauthn: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
323
263
|
const { email, passwordHash, device, authId } = event.payload;
|
|
@@ -349,13 +289,12 @@ export class AloreAuth {
|
|
|
349
289
|
passwordHash,
|
|
350
290
|
device,
|
|
351
291
|
credential,
|
|
352
|
-
sessionId: optionsData.sessionId,
|
|
353
292
|
}),
|
|
354
293
|
});
|
|
355
294
|
const data = yield response.json();
|
|
356
295
|
if (response.ok)
|
|
357
296
|
return data;
|
|
358
|
-
|
|
297
|
+
yield this.throwParsedResponseError(response);
|
|
359
298
|
}),
|
|
360
299
|
verifyDeviceCode: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
361
300
|
const { email, passwordHash, device, secureCode } = event.payload;
|
|
@@ -369,7 +308,6 @@ export class AloreAuth {
|
|
|
369
308
|
passwordHash,
|
|
370
309
|
deviceSecret: device,
|
|
371
310
|
emailCode: secureCode,
|
|
372
|
-
sessionId: context.sessionId,
|
|
373
311
|
}),
|
|
374
312
|
});
|
|
375
313
|
const data = yield response.json();
|
|
@@ -380,9 +318,6 @@ export class AloreAuth {
|
|
|
380
318
|
verifyEmail2fa: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
381
319
|
const { email, passwordHash, secureCode } = event.payload;
|
|
382
320
|
const { credentialEmail, authProviderConfigs } = context;
|
|
383
|
-
if (!this.services.isEmailAllowed(context, email || credentialEmail)) {
|
|
384
|
-
throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
|
|
385
|
-
}
|
|
386
321
|
const { firebaseCompatible } = authProviderConfigs || {};
|
|
387
322
|
const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/email-2fa-verification${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
|
|
388
323
|
method: 'POST',
|
|
@@ -390,7 +325,6 @@ export class AloreAuth {
|
|
|
390
325
|
email: email || credentialEmail,
|
|
391
326
|
passwordHash,
|
|
392
327
|
emailCode: secureCode,
|
|
393
|
-
sessionId: context.sessionId,
|
|
394
328
|
}),
|
|
395
329
|
headers: {
|
|
396
330
|
'Content-Type': 'application/json',
|
|
@@ -414,7 +348,7 @@ export class AloreAuth {
|
|
|
414
348
|
});
|
|
415
349
|
const data = yield response.json();
|
|
416
350
|
if (!response.ok)
|
|
417
|
-
|
|
351
|
+
yield this.throwParsedResponseError(response);
|
|
418
352
|
return data;
|
|
419
353
|
}),
|
|
420
354
|
verifyClaimNftEmail2fa: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -424,7 +358,6 @@ export class AloreAuth {
|
|
|
424
358
|
body: JSON.stringify({
|
|
425
359
|
email,
|
|
426
360
|
emailCode,
|
|
427
|
-
sessionId: context.sessionId,
|
|
428
361
|
}),
|
|
429
362
|
headers: {
|
|
430
363
|
'Content-Type': 'application/json',
|
|
@@ -433,14 +366,13 @@ export class AloreAuth {
|
|
|
433
366
|
const data = yield response.json();
|
|
434
367
|
if (response.ok)
|
|
435
368
|
return data;
|
|
436
|
-
|
|
369
|
+
yield this.throwParsedResponseError(response);
|
|
437
370
|
}),
|
|
438
371
|
fetchForgeData: (_, event) => __awaiter(this, void 0, void 0, function* () {
|
|
439
372
|
const response = yield this.fetchWithProgressiveBackoff(`/forges/${event.forgeId}`);
|
|
440
373
|
const data = (yield response.json());
|
|
441
|
-
if (!response.ok)
|
|
442
|
-
|
|
443
|
-
}
|
|
374
|
+
if (!response.ok)
|
|
375
|
+
yield this.throwParsedResponseError(response);
|
|
444
376
|
return data;
|
|
445
377
|
}),
|
|
446
378
|
// Google login flow
|
|
@@ -460,9 +392,6 @@ export class AloreAuth {
|
|
|
460
392
|
});
|
|
461
393
|
const data = yield response.json();
|
|
462
394
|
if (response.ok) {
|
|
463
|
-
if (!this.services.isEmailAllowed(context, data.email)) {
|
|
464
|
-
throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
|
|
465
|
-
}
|
|
466
395
|
return {
|
|
467
396
|
googleOtpCode: data.otpCode,
|
|
468
397
|
salt: data.salt,
|
|
@@ -471,13 +400,9 @@ export class AloreAuth {
|
|
|
471
400
|
nickname: data.nickname,
|
|
472
401
|
salt: data.salt,
|
|
473
402
|
},
|
|
474
|
-
sessionId: data.sessionId,
|
|
475
403
|
};
|
|
476
404
|
}
|
|
477
405
|
if (response.status === 404) {
|
|
478
|
-
if (!this.services.isEmailAllowed(context, data.email)) {
|
|
479
|
-
throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
|
|
480
|
-
}
|
|
481
406
|
return {
|
|
482
407
|
isNewUser: true,
|
|
483
408
|
socialProviderRegisterUser: {
|
|
@@ -488,7 +413,7 @@ export class AloreAuth {
|
|
|
488
413
|
};
|
|
489
414
|
}
|
|
490
415
|
if (!response.ok)
|
|
491
|
-
|
|
416
|
+
yield this.throwParsedResponseError(response);
|
|
492
417
|
return {};
|
|
493
418
|
}),
|
|
494
419
|
verifyGoogleLogin: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -499,7 +424,6 @@ export class AloreAuth {
|
|
|
499
424
|
email,
|
|
500
425
|
emailCode: otp,
|
|
501
426
|
passwordHash,
|
|
502
|
-
sessionId: context.sessionId,
|
|
503
427
|
}),
|
|
504
428
|
headers: {
|
|
505
429
|
'Content-Type': 'application/json',
|
|
@@ -593,6 +517,44 @@ export class AloreAuth {
|
|
|
593
517
|
throw new AloreAuthError(ErrorTypes.FAILED_TO_FETCH, `Max attempts (${maxAttempts}) exceeded while contacting ${this.aloreBaseUrl}${url}`);
|
|
594
518
|
});
|
|
595
519
|
}
|
|
520
|
+
// eslint-disable-next-line class-methods-use-this
|
|
521
|
+
parseErrorResponse(response) {
|
|
522
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
523
|
+
try {
|
|
524
|
+
const data = yield response.json();
|
|
525
|
+
// Standardize to server payload when present
|
|
526
|
+
if (data && typeof data === 'object' && (data.message || data.status)) {
|
|
527
|
+
return {
|
|
528
|
+
status: data.status || response.status,
|
|
529
|
+
message: data.message || data.error || response.statusText,
|
|
530
|
+
timestamp: data.timestamp,
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
return { status: response.status, message: response.statusText };
|
|
534
|
+
}
|
|
535
|
+
catch (_a) {
|
|
536
|
+
return { status: response.status, message: response.statusText };
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
// eslint-disable-next-line class-methods-use-this
|
|
541
|
+
throwParsedResponseError(response) {
|
|
542
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
543
|
+
const parsed = yield this.parseErrorResponse(response);
|
|
544
|
+
// Normalize well-known auth errors for consistent UI handling
|
|
545
|
+
let normalizedMessage = parsed.message || 'Request failed';
|
|
546
|
+
if (parsed.status === 401) {
|
|
547
|
+
normalizedMessage = 'INVALID_CREDENTIALS';
|
|
548
|
+
}
|
|
549
|
+
else if (parsed.status === 403 && parsed.message === 'EMAIL_NOT_ALLOWED') {
|
|
550
|
+
normalizedMessage = 'EMAIL_NOT_ALLOWED';
|
|
551
|
+
}
|
|
552
|
+
const err = new AloreAuthError(ErrorTypes.FAILED_TO_FETCH, normalizedMessage);
|
|
553
|
+
// @ts-ignore attach server payload for consumers
|
|
554
|
+
err.data = Object.assign(Object.assign({}, parsed), { message: normalizedMessage });
|
|
555
|
+
throw err;
|
|
556
|
+
});
|
|
557
|
+
}
|
|
596
558
|
verifyBackendStatus() {
|
|
597
559
|
return __awaiter(this, void 0, void 0, function* () {
|
|
598
560
|
const endpoint = '/health/ready';
|