@alore/auth-react-sdk 1.1.0-alpha.7 → 1.1.0-alpha.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/dist/types.d.ts +0 -1
- package/dist/utils/AloreAuth.d.ts +2 -5
- package/dist/utils/AloreAuth.js +21 -25
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -58,7 +58,6 @@ export declare class AloreAuth {
|
|
|
58
58
|
};
|
|
59
59
|
}) => Promise<{
|
|
60
60
|
salt: any;
|
|
61
|
-
sessionId: any;
|
|
62
61
|
} | undefined>;
|
|
63
62
|
sendCode: (context: AuthMachineContext, event: {
|
|
64
63
|
type: 'SEND_CODE';
|
|
@@ -85,7 +84,7 @@ export declare class AloreAuth {
|
|
|
85
84
|
isForgeClaim?: boolean | undefined;
|
|
86
85
|
locale?: string | undefined;
|
|
87
86
|
};
|
|
88
|
-
}) => Promise<
|
|
87
|
+
}) => Promise<{}>;
|
|
89
88
|
startRegisterPasskey: (context: AuthMachineContext, event: {
|
|
90
89
|
type: 'START_PASSKEY_REGISTER';
|
|
91
90
|
payload: {
|
|
@@ -214,7 +213,6 @@ export declare class AloreAuth {
|
|
|
214
213
|
nickname: any;
|
|
215
214
|
salt: any;
|
|
216
215
|
};
|
|
217
|
-
sessionId: any;
|
|
218
216
|
isNewUser?: undefined;
|
|
219
217
|
socialProviderRegisterUser?: undefined;
|
|
220
218
|
} | {
|
|
@@ -227,12 +225,10 @@ export declare class AloreAuth {
|
|
|
227
225
|
googleOtpCode?: undefined;
|
|
228
226
|
salt?: undefined;
|
|
229
227
|
googleUser?: undefined;
|
|
230
|
-
sessionId?: undefined;
|
|
231
228
|
} | {
|
|
232
229
|
googleOtpCode?: undefined;
|
|
233
230
|
salt?: undefined;
|
|
234
231
|
googleUser?: undefined;
|
|
235
|
-
sessionId?: undefined;
|
|
236
232
|
isNewUser?: undefined;
|
|
237
233
|
socialProviderRegisterUser?: undefined;
|
|
238
234
|
}>;
|
|
@@ -246,6 +242,7 @@ export declare class AloreAuth {
|
|
|
246
242
|
}) => Promise<any>;
|
|
247
243
|
};
|
|
248
244
|
private delay;
|
|
245
|
+
private isLocalUrl;
|
|
249
246
|
fetchWithProgressiveBackoff(url: RequestInfo | URL, options?: RequestInit, config?: FetchWithProgressiveBackoffConfig): Promise<Response>;
|
|
250
247
|
private parseErrorResponse;
|
|
251
248
|
private throwParsedResponseError;
|
package/dist/utils/AloreAuth.js
CHANGED
|
@@ -47,7 +47,6 @@ export class AloreAuth {
|
|
|
47
47
|
},
|
|
48
48
|
body: JSON.stringify({
|
|
49
49
|
emailCode: secureCode,
|
|
50
|
-
sessionId: context.sessionId,
|
|
51
50
|
}),
|
|
52
51
|
});
|
|
53
52
|
if (response.ok) {
|
|
@@ -113,8 +112,8 @@ export class AloreAuth {
|
|
|
113
112
|
});
|
|
114
113
|
if (response.ok) {
|
|
115
114
|
const resJson = yield response.json();
|
|
116
|
-
const { salt
|
|
117
|
-
return { salt
|
|
115
|
+
const { salt } = resJson;
|
|
116
|
+
return { salt };
|
|
118
117
|
}
|
|
119
118
|
// Throw parsed error for machine to consume
|
|
120
119
|
yield this.throwParsedResponseError(response);
|
|
@@ -135,7 +134,6 @@ export class AloreAuth {
|
|
|
135
134
|
return {};
|
|
136
135
|
}),
|
|
137
136
|
verifyLogin: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
138
|
-
var _a, _b;
|
|
139
137
|
const { email, passwordHash, device, locale } = event.payload;
|
|
140
138
|
const { credentialEmail } = context;
|
|
141
139
|
const searchParams = new URLSearchParams();
|
|
@@ -157,19 +155,10 @@ export class AloreAuth {
|
|
|
157
155
|
device,
|
|
158
156
|
}),
|
|
159
157
|
});
|
|
160
|
-
const data = yield response.json();
|
|
161
158
|
if (!response.ok) {
|
|
162
|
-
if (response.status === 403) {
|
|
163
|
-
return { active2fa: data };
|
|
164
|
-
}
|
|
165
|
-
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'))) {
|
|
166
|
-
return { error: data === null || data === void 0 ? void 0 : data.error };
|
|
167
|
-
}
|
|
168
159
|
yield this.throwParsedResponseError(response);
|
|
169
160
|
}
|
|
170
|
-
|
|
171
|
-
return data;
|
|
172
|
-
}
|
|
161
|
+
return {};
|
|
173
162
|
}),
|
|
174
163
|
// Passkey registration flow
|
|
175
164
|
startRegisterPasskey: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -205,7 +194,6 @@ export class AloreAuth {
|
|
|
205
194
|
userNickname: nickname || null,
|
|
206
195
|
userDevice: device,
|
|
207
196
|
passkeyRegistration,
|
|
208
|
-
sessionId: context.sessionId,
|
|
209
197
|
rpOrigin: rpDomain,
|
|
210
198
|
}),
|
|
211
199
|
});
|
|
@@ -215,9 +203,9 @@ export class AloreAuth {
|
|
|
215
203
|
}),
|
|
216
204
|
// Passkey login flow
|
|
217
205
|
startPasskeyAuth: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
218
|
-
var
|
|
206
|
+
var _a;
|
|
219
207
|
const { rpDomain } = context.authProviderConfigs || {};
|
|
220
|
-
const email = (
|
|
208
|
+
const email = (_a = event.payload) === null || _a === void 0 ? void 0 : _a.email;
|
|
221
209
|
const searchParams = new URLSearchParams();
|
|
222
210
|
const url = '/auth/v1/login-passkey';
|
|
223
211
|
if (rpDomain) {
|
|
@@ -243,7 +231,6 @@ export class AloreAuth {
|
|
|
243
231
|
},
|
|
244
232
|
body: JSON.stringify({
|
|
245
233
|
passkeyAuth,
|
|
246
|
-
sessionId: context.sessionId,
|
|
247
234
|
rpOrigin: rpDomain,
|
|
248
235
|
}),
|
|
249
236
|
});
|
|
@@ -302,7 +289,6 @@ export class AloreAuth {
|
|
|
302
289
|
passwordHash,
|
|
303
290
|
device,
|
|
304
291
|
credential,
|
|
305
|
-
sessionId: optionsData.sessionId,
|
|
306
292
|
}),
|
|
307
293
|
});
|
|
308
294
|
const data = yield response.json();
|
|
@@ -322,7 +308,6 @@ export class AloreAuth {
|
|
|
322
308
|
passwordHash,
|
|
323
309
|
deviceSecret: device,
|
|
324
310
|
emailCode: secureCode,
|
|
325
|
-
sessionId: context.sessionId,
|
|
326
311
|
}),
|
|
327
312
|
});
|
|
328
313
|
const data = yield response.json();
|
|
@@ -340,7 +325,6 @@ export class AloreAuth {
|
|
|
340
325
|
email: email || credentialEmail,
|
|
341
326
|
passwordHash,
|
|
342
327
|
emailCode: secureCode,
|
|
343
|
-
sessionId: context.sessionId,
|
|
344
328
|
}),
|
|
345
329
|
headers: {
|
|
346
330
|
'Content-Type': 'application/json',
|
|
@@ -374,7 +358,6 @@ export class AloreAuth {
|
|
|
374
358
|
body: JSON.stringify({
|
|
375
359
|
email,
|
|
376
360
|
emailCode,
|
|
377
|
-
sessionId: context.sessionId,
|
|
378
361
|
}),
|
|
379
362
|
headers: {
|
|
380
363
|
'Content-Type': 'application/json',
|
|
@@ -417,7 +400,6 @@ export class AloreAuth {
|
|
|
417
400
|
nickname: data.nickname,
|
|
418
401
|
salt: data.salt,
|
|
419
402
|
},
|
|
420
|
-
sessionId: data.sessionId,
|
|
421
403
|
};
|
|
422
404
|
}
|
|
423
405
|
if (response.status === 404) {
|
|
@@ -442,7 +424,6 @@ export class AloreAuth {
|
|
|
442
424
|
email,
|
|
443
425
|
emailCode: otp,
|
|
444
426
|
passwordHash,
|
|
445
|
-
sessionId: context.sessionId,
|
|
446
427
|
}),
|
|
447
428
|
headers: {
|
|
448
429
|
'Content-Type': 'application/json',
|
|
@@ -467,6 +448,21 @@ export class AloreAuth {
|
|
|
467
448
|
yield new Promise((resolve) => setTimeout(resolve, ms));
|
|
468
449
|
});
|
|
469
450
|
}
|
|
451
|
+
// eslint-disable-next-line class-methods-use-this
|
|
452
|
+
isLocalUrl(urlString) {
|
|
453
|
+
try {
|
|
454
|
+
const parsed = new URL(urlString);
|
|
455
|
+
const isHttp = parsed.protocol === 'http:';
|
|
456
|
+
const isLoopbackHost = parsed.hostname === 'localhost' ||
|
|
457
|
+
parsed.hostname === '127.0.0.1' ||
|
|
458
|
+
parsed.hostname === '::1';
|
|
459
|
+
const isPort8000 = parsed.port === '8000';
|
|
460
|
+
return isHttp || isLoopbackHost || isPort8000;
|
|
461
|
+
}
|
|
462
|
+
catch (_e) {
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
470
466
|
fetchWithProgressiveBackoff(
|
|
471
467
|
// eslint-disable-next-line no-undef
|
|
472
468
|
url,
|
|
@@ -476,7 +472,7 @@ export class AloreAuth {
|
|
|
476
472
|
const { maxAttempts = 3, initialDelay = 200 } = config || {};
|
|
477
473
|
let attempt = 0;
|
|
478
474
|
let delayValue = initialDelay;
|
|
479
|
-
const isLocal = this.
|
|
475
|
+
const isLocal = this.isLocalUrl(this.aloreBaseUrl);
|
|
480
476
|
// eslint-disable-next-line no-undef
|
|
481
477
|
const init = Object.assign(Object.assign({}, options), { credentials: 'include', headers: Object.assign(Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.headers), { 'X-CLIENT-ID': this.clientId }), (isLocal && { 'CF-Connecting-IP': '127.0.0.1' })) });
|
|
482
478
|
while (attempt < maxAttempts) {
|