@alore/auth-react-sdk 1.1.0-alpha.11 → 1.1.0-alpha.13
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/utils/AloreAuth.d.ts +2 -0
- package/dist/utils/AloreAuth.js +21 -14
- package/package.json +2 -2
package/dist/utils/AloreAuth.js
CHANGED
|
@@ -152,16 +152,18 @@ export class AloreAuth {
|
|
|
152
152
|
if (this.emailTemplate !== '') {
|
|
153
153
|
searchParams.append('template', this.emailTemplate);
|
|
154
154
|
}
|
|
155
|
+
// Include device trust token if available (to skip email 2FA on trusted devices)
|
|
156
|
+
let trustToken = null;
|
|
157
|
+
if (typeof window !== 'undefined') {
|
|
158
|
+
trustToken = window.localStorage.getItem('deviceTrustToken');
|
|
159
|
+
}
|
|
155
160
|
const response = yield this.fetchWithProgressiveBackoff(searchParams.size > 0 ? `${url}?${searchParams.toString()}` : url, {
|
|
156
161
|
method: 'POST',
|
|
157
162
|
headers: {
|
|
158
163
|
'Content-Type': 'application/json',
|
|
159
164
|
},
|
|
160
|
-
body: JSON.stringify({
|
|
161
|
-
|
|
162
|
-
passwordHash,
|
|
163
|
-
device,
|
|
164
|
-
}),
|
|
165
|
+
body: JSON.stringify(Object.assign({ email: email || credentialEmail, passwordHash,
|
|
166
|
+
device }, (trustToken && { trustToken }))),
|
|
165
167
|
});
|
|
166
168
|
const data = yield response.json();
|
|
167
169
|
if (!response.ok) {
|
|
@@ -295,7 +297,9 @@ export class AloreAuth {
|
|
|
295
297
|
throw new Error(optionsResponse.statusText);
|
|
296
298
|
}
|
|
297
299
|
const optionsData = yield optionsResponse.json();
|
|
298
|
-
const credential = yield startAuthentication(
|
|
300
|
+
const credential = yield startAuthentication({
|
|
301
|
+
optionsJSON: optionsData.requestChallengeResponse.publicKey,
|
|
302
|
+
}).catch((err) => {
|
|
299
303
|
throw new Error(err);
|
|
300
304
|
});
|
|
301
305
|
const response = yield this.fetchWithProgressiveBackoff('/auth/v1/hw-2fa-finish-verification', {
|
|
@@ -337,24 +341,27 @@ export class AloreAuth {
|
|
|
337
341
|
throw new Error(data.message || data.error || 'Authentication failed');
|
|
338
342
|
}),
|
|
339
343
|
verifyEmail2fa: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
340
|
-
const { email, passwordHash, secureCode } = event.payload;
|
|
344
|
+
const { email, passwordHash, secureCode, device, trustThisDevice } = event.payload;
|
|
341
345
|
const { credentialEmail, authProviderConfigs } = context;
|
|
342
346
|
const { firebaseCompatible } = authProviderConfigs || {};
|
|
343
347
|
const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/email-2fa-verification${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
|
|
344
348
|
method: 'POST',
|
|
345
|
-
body: JSON.stringify({
|
|
346
|
-
email: email || credentialEmail,
|
|
347
|
-
passwordHash,
|
|
348
|
-
emailCode: secureCode,
|
|
349
|
-
sessionId: context.sessionId,
|
|
350
|
-
}),
|
|
349
|
+
body: JSON.stringify(Object.assign(Object.assign({ email: email || credentialEmail, passwordHash, emailCode: secureCode, sessionId: context.sessionId }, (device && { device })), (trustThisDevice !== undefined && { trustThisDevice }))),
|
|
351
350
|
headers: {
|
|
352
351
|
'Content-Type': 'application/json',
|
|
353
352
|
},
|
|
354
353
|
});
|
|
355
354
|
const data = yield response.json();
|
|
356
|
-
if (response.ok)
|
|
355
|
+
if (response.ok) {
|
|
356
|
+
// Persist device trust token for future logins
|
|
357
|
+
if (data.deviceTrustToken && typeof window !== 'undefined') {
|
|
358
|
+
window.localStorage.setItem('deviceTrustToken', data.deviceTrustToken);
|
|
359
|
+
}
|
|
360
|
+
else if (typeof window !== 'undefined') {
|
|
361
|
+
window.localStorage.removeItem('deviceTrustToken');
|
|
362
|
+
}
|
|
357
363
|
return data;
|
|
364
|
+
}
|
|
358
365
|
throw new Error(data.message || data.error || 'Authentication failed');
|
|
359
366
|
}),
|
|
360
367
|
verifyEmailEligibility: (_, event) => __awaiter(this, void 0, void 0, function* () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alore/auth-react-sdk",
|
|
3
|
-
"version": "1.1.0-alpha.
|
|
3
|
+
"version": "1.1.0-alpha.13",
|
|
4
4
|
"repository": "https://github.com/0xCarbon/alore-js",
|
|
5
5
|
"description": "SDK for Alore Auth",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"node": ">=20.0.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@simplewebauthn/browser": "
|
|
23
|
+
"@simplewebauthn/browser": "13.3.0",
|
|
24
24
|
"argon2-browser": "1.18.0",
|
|
25
25
|
"ethers": "6.7.1",
|
|
26
26
|
"js-cookie": "3.0.5",
|