@alore/auth-react-sdk 1.1.0-alpha.10 → 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.
@@ -34,8 +34,9 @@ export declare class AloreAuth {
34
34
  confirmPassword: (context: AuthMachineContext, event: {
35
35
  type: 'CONFIRM_PASSWORD';
36
36
  payload: {
37
- email: string;
37
+ salt: string;
38
38
  passwordHash: string;
39
+ token: string;
39
40
  };
40
41
  }) => Promise<{}>;
41
42
  sendConfirmationEmail: (context: AuthMachineContext, event: {
@@ -64,6 +65,7 @@ export declare class AloreAuth {
64
65
  type: 'SEND_CODE';
65
66
  payload: {
66
67
  email: string;
68
+ locale?: string;
67
69
  };
68
70
  }) => Promise<{}>;
69
71
  verifyLogin: (context: AuthMachineContext, event: {
@@ -181,6 +183,8 @@ export declare class AloreAuth {
181
183
  email: string;
182
184
  secureCode: string;
183
185
  passwordHash: string;
186
+ device?: string;
187
+ trustThisDevice?: boolean;
184
188
  };
185
189
  }) => Promise<any>;
186
190
  verifyEmailEligibility: (_: AuthMachineContext, event: {
@@ -76,15 +76,16 @@ export class AloreAuth {
76
76
  yield this.throwParsedResponseError(response);
77
77
  }),
78
78
  confirmPassword: (context, event) => __awaiter(this, void 0, void 0, function* () {
79
- const { email, passwordHash } = event.payload;
80
- const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/password-creation`, {
79
+ const { salt, passwordHash, token } = event.payload;
80
+ const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/reset-password`, {
81
81
  method: 'POST',
82
82
  headers: {
83
83
  'Content-Type': 'application/json',
84
84
  },
85
85
  body: JSON.stringify({
86
- email,
87
- newPasswordHash: passwordHash,
86
+ token,
87
+ salt,
88
+ newPassword: passwordHash,
88
89
  }),
89
90
  });
90
91
  if (!response.ok)
@@ -120,8 +121,13 @@ export class AloreAuth {
120
121
  yield this.throwParsedResponseError(response);
121
122
  }),
122
123
  sendCode: (context, event) => __awaiter(this, void 0, void 0, function* () {
123
- const { email } = event.payload;
124
- const response = yield this.fetchWithProgressiveBackoff(`/reset-password`, {
124
+ const { email, locale } = event.payload;
125
+ const searchParams = new URLSearchParams();
126
+ const url = '/auth/v1/request-password-reset';
127
+ if (locale) {
128
+ searchParams.append('locale', locale);
129
+ }
130
+ const response = yield this.fetchWithProgressiveBackoff(searchParams.size > 0 ? `${url}?${searchParams.toString()}` : url, {
125
131
  method: 'POST',
126
132
  headers: {
127
133
  'Content-Type': 'application/json',
@@ -146,16 +152,18 @@ export class AloreAuth {
146
152
  if (this.emailTemplate !== '') {
147
153
  searchParams.append('template', this.emailTemplate);
148
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
+ }
149
160
  const response = yield this.fetchWithProgressiveBackoff(searchParams.size > 0 ? `${url}?${searchParams.toString()}` : url, {
150
161
  method: 'POST',
151
162
  headers: {
152
163
  'Content-Type': 'application/json',
153
164
  },
154
- body: JSON.stringify({
155
- email: email || credentialEmail,
156
- passwordHash,
157
- device,
158
- }),
165
+ body: JSON.stringify(Object.assign({ email: email || credentialEmail, passwordHash,
166
+ device }, (trustToken && { trustToken }))),
159
167
  });
160
168
  const data = yield response.json();
161
169
  if (!response.ok) {
@@ -331,24 +339,27 @@ export class AloreAuth {
331
339
  throw new Error(data.message || data.error || 'Authentication failed');
332
340
  }),
333
341
  verifyEmail2fa: (context, event) => __awaiter(this, void 0, void 0, function* () {
334
- const { email, passwordHash, secureCode } = event.payload;
342
+ const { email, passwordHash, secureCode, device, trustThisDevice } = event.payload;
335
343
  const { credentialEmail, authProviderConfigs } = context;
336
344
  const { firebaseCompatible } = authProviderConfigs || {};
337
345
  const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/email-2fa-verification${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
338
346
  method: 'POST',
339
- body: JSON.stringify({
340
- email: email || credentialEmail,
341
- passwordHash,
342
- emailCode: secureCode,
343
- sessionId: context.sessionId,
344
- }),
347
+ body: JSON.stringify(Object.assign(Object.assign({ email: email || credentialEmail, passwordHash, emailCode: secureCode, sessionId: context.sessionId }, (device && { device })), (trustThisDevice !== undefined && { trustThisDevice }))),
345
348
  headers: {
346
349
  'Content-Type': 'application/json',
347
350
  },
348
351
  });
349
352
  const data = yield response.json();
350
- 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
+ }
351
361
  return data;
362
+ }
352
363
  throw new Error(data.message || data.error || 'Authentication failed');
353
364
  }),
354
365
  verifyEmailEligibility: (_, event) => __awaiter(this, void 0, void 0, function* () {
@@ -577,7 +588,7 @@ export class AloreAuth {
577
588
  const parsed = yield this.parseErrorResponse(response);
578
589
  // Normalize well-known auth errors for consistent UI handling
579
590
  let normalizedMessage = parsed.message || 'Request failed';
580
- if (parsed.status === 401) {
591
+ if (parsed.status === 401 && parsed.message !== 'INVALID_SESSION') {
581
592
  normalizedMessage = 'INVALID_CREDENTIALS';
582
593
  }
583
594
  else if (parsed.status === 403 && parsed.message === 'EMAIL_NOT_ALLOWED') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alore/auth-react-sdk",
3
- "version": "1.1.0-alpha.10",
3
+ "version": "1.1.0-alpha.12",
4
4
  "repository": "https://github.com/0xCarbon/alore-js",
5
5
  "description": "SDK for Alore Auth",
6
6
  "main": "dist/index.js",