@alore/auth-react-sdk 1.1.0-alpha.11 → 1.1.0-alpha.12
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 +18 -13
- package/package.json +1 -1
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) {
|
|
@@ -337,24 +339,27 @@ export class AloreAuth {
|
|
|
337
339
|
throw new Error(data.message || data.error || 'Authentication failed');
|
|
338
340
|
}),
|
|
339
341
|
verifyEmail2fa: (context, event) => __awaiter(this, void 0, void 0, function* () {
|
|
340
|
-
const { email, passwordHash, secureCode } = event.payload;
|
|
342
|
+
const { email, passwordHash, secureCode, device, trustThisDevice } = event.payload;
|
|
341
343
|
const { credentialEmail, authProviderConfigs } = context;
|
|
342
344
|
const { firebaseCompatible } = authProviderConfigs || {};
|
|
343
345
|
const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/email-2fa-verification${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
|
|
344
346
|
method: 'POST',
|
|
345
|
-
body: JSON.stringify({
|
|
346
|
-
email: email || credentialEmail,
|
|
347
|
-
passwordHash,
|
|
348
|
-
emailCode: secureCode,
|
|
349
|
-
sessionId: context.sessionId,
|
|
350
|
-
}),
|
|
347
|
+
body: JSON.stringify(Object.assign(Object.assign({ email: email || credentialEmail, passwordHash, emailCode: secureCode, sessionId: context.sessionId }, (device && { device })), (trustThisDevice !== undefined && { trustThisDevice }))),
|
|
351
348
|
headers: {
|
|
352
349
|
'Content-Type': 'application/json',
|
|
353
350
|
},
|
|
354
351
|
});
|
|
355
352
|
const data = yield response.json();
|
|
356
|
-
if (response.ok)
|
|
353
|
+
if (response.ok) {
|
|
354
|
+
// Persist device trust token for future logins
|
|
355
|
+
if (data.deviceTrustToken && typeof window !== 'undefined') {
|
|
356
|
+
window.localStorage.setItem('deviceTrustToken', data.deviceTrustToken);
|
|
357
|
+
}
|
|
358
|
+
else if (typeof window !== 'undefined') {
|
|
359
|
+
window.localStorage.removeItem('deviceTrustToken');
|
|
360
|
+
}
|
|
357
361
|
return data;
|
|
362
|
+
}
|
|
358
363
|
throw new Error(data.message || data.error || 'Authentication failed');
|
|
359
364
|
}),
|
|
360
365
|
verifyEmailEligibility: (_, event) => __awaiter(this, void 0, void 0, function* () {
|