@alore/auth-react-sdk 1.1.0-alpha.3 → 1.1.0-alpha.5

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.
@@ -48,7 +48,7 @@ export class AloreAuth {
48
48
  retrieveSalt: (context, event) => __awaiter(this, void 0, void 0, function* () {
49
49
  const { email } = event.payload;
50
50
  if (!this.services.isEmailAllowed(context, email)) {
51
- throw new Error('Email domain not allowed');
51
+ throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
52
52
  }
53
53
  const { credentialEmail } = context;
54
54
  const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/salt/${email || credentialEmail}`, {
@@ -83,7 +83,7 @@ export class AloreAuth {
83
83
  completeRegistration: (context, event) => __awaiter(this, void 0, void 0, function* () {
84
84
  const { email, nickname, passwordHash, device } = event.payload;
85
85
  if (!this.services.isEmailAllowed(context, email)) {
86
- throw new Error('Email domain not allowed');
86
+ throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
87
87
  }
88
88
  const { firebaseCompatible } = context.authProviderConfigs || {};
89
89
  const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/account-registration${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
@@ -122,7 +122,7 @@ export class AloreAuth {
122
122
  sendConfirmationEmail: (context, event) => __awaiter(this, void 0, void 0, function* () {
123
123
  const { email, nickname, locale } = event.payload;
124
124
  if (!this.services.isEmailAllowed(context, email)) {
125
- throw new Error('Email domain not allowed');
125
+ throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
126
126
  }
127
127
  const searchParams = new URLSearchParams();
128
128
  const url = '/auth/v1/confirmation-email';
@@ -156,7 +156,7 @@ export class AloreAuth {
156
156
  sendCode: (context, event) => __awaiter(this, void 0, void 0, function* () {
157
157
  const { email } = event.payload;
158
158
  if (!this.services.isEmailAllowed(context, email)) {
159
- return { error: 'Email domain not allowed' };
159
+ throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
160
160
  }
161
161
  const response = yield this.fetchWithProgressiveBackoff(`/reset-password`, {
162
162
  method: 'POST',
@@ -175,7 +175,7 @@ export class AloreAuth {
175
175
  var _a, _b;
176
176
  const { email, passwordHash, device, locale } = event.payload;
177
177
  if (!this.services.isEmailAllowed(context, email || context.credentialEmail)) {
178
- throw new Error('Email domain not allowed');
178
+ throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
179
179
  }
180
180
  const { credentialEmail } = context;
181
181
  const searchParams = new URLSearchParams();
@@ -216,7 +216,7 @@ export class AloreAuth {
216
216
  const { rpDomain } = context.authProviderConfigs || {};
217
217
  const { email, nickname, device } = event.payload || context.registerUser;
218
218
  if (email && !this.services.isEmailAllowed(context, email)) {
219
- throw new Error('Email domain not allowed');
219
+ throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
220
220
  }
221
221
  const startPasskeyRegistrationResponse = yield this.fetchWithProgressiveBackoff('/auth/v1/account-registration-passkey', {
222
222
  method: 'POST',
@@ -237,7 +237,7 @@ export class AloreAuth {
237
237
  const { rpDomain } = context.authProviderConfigs || {};
238
238
  const { email, nickname, device, passkeyRegistration } = event.payload || {};
239
239
  if (email && !this.services.isEmailAllowed(context, email)) {
240
- throw new Error('Email domain not allowed');
240
+ throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
241
241
  }
242
242
  const response = yield this.fetchWithProgressiveBackoff('/auth/v1/account-registration-passkey-finish', {
243
243
  method: 'POST',
@@ -263,7 +263,7 @@ export class AloreAuth {
263
263
  const { rpDomain } = context.authProviderConfigs || {};
264
264
  const email = (_c = event.payload) === null || _c === void 0 ? void 0 : _c.email;
265
265
  if (email && !this.services.isEmailAllowed(context, email)) {
266
- throw new Error('Email domain not allowed');
266
+ throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
267
267
  }
268
268
  const searchParams = new URLSearchParams();
269
269
  const url = '/auth/v1/login-passkey';
@@ -381,7 +381,7 @@ export class AloreAuth {
381
381
  const { email, passwordHash, secureCode } = event.payload;
382
382
  const { credentialEmail, authProviderConfigs } = context;
383
383
  if (!this.services.isEmailAllowed(context, email || credentialEmail)) {
384
- throw new Error('Email domain not allowed');
384
+ throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
385
385
  }
386
386
  const { firebaseCompatible } = authProviderConfigs || {};
387
387
  const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/email-2fa-verification${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
@@ -461,7 +461,7 @@ export class AloreAuth {
461
461
  const data = yield response.json();
462
462
  if (response.ok) {
463
463
  if (!this.services.isEmailAllowed(context, data.email)) {
464
- throw new Error('Email domain not allowed');
464
+ throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
465
465
  }
466
466
  return {
467
467
  googleOtpCode: data.otpCode,
@@ -476,7 +476,7 @@ export class AloreAuth {
476
476
  }
477
477
  if (response.status === 404) {
478
478
  if (!this.services.isEmailAllowed(context, data.email)) {
479
- throw new Error('Email domain not allowed');
479
+ throw new AloreAuthError(ErrorTypes.EMAIL_DOMAIN_NOT_ALLOWED, 'Email domain not allowed', 400);
480
480
  }
481
481
  return {
482
482
  isNewUser: true,
@@ -533,8 +533,9 @@ export class AloreAuth {
533
533
  const { maxAttempts = 3, initialDelay = 200 } = config || {};
534
534
  let attempt = 0;
535
535
  let delayValue = initialDelay;
536
+ const isLocal = this.aloreBaseUrl.includes('localhost') || this.aloreBaseUrl.includes('127.0.0.1');
536
537
  // eslint-disable-next-line no-undef
537
- const init = Object.assign(Object.assign({}, options), { credentials: 'include', headers: Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.headers), { 'X-CLIENT-ID': this.clientId, 'CF-Connecting-IP': '127.0.0.1' }) });
538
+ 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' })) });
538
539
  while (attempt < maxAttempts) {
539
540
  if (attempt > 0) {
540
541
  // eslint-disable-next-line no-await-in-loop, no-promise-executor-return, no-loop-func
@@ -5,6 +5,7 @@ export declare enum ErrorCodes {
5
5
  }
6
6
  export declare enum ErrorTypes {
7
7
  CLIENT_ID_REQUIRED = "CLIENT_ID_REQUIRED",
8
+ EMAIL_DOMAIN_NOT_ALLOWED = "EMAIL_DOMAIN_NOT_ALLOWED",
8
9
  PASSKEY_NOT_SUPPORTED = "PASSKEY_NOT_SUPPORTED",
9
10
  USER_ALREADY_EXISTS = "USER_ALREADY_EXISTS",
10
11
  FAILED_TO_FETCH = "FAILED_TO_FETCH",
@@ -8,6 +8,7 @@ export var ErrorCodes;
8
8
  export var ErrorTypes;
9
9
  (function (ErrorTypes) {
10
10
  ErrorTypes["CLIENT_ID_REQUIRED"] = "CLIENT_ID_REQUIRED";
11
+ ErrorTypes["EMAIL_DOMAIN_NOT_ALLOWED"] = "EMAIL_DOMAIN_NOT_ALLOWED";
11
12
  ErrorTypes["PASSKEY_NOT_SUPPORTED"] = "PASSKEY_NOT_SUPPORTED";
12
13
  ErrorTypes["USER_ALREADY_EXISTS"] = "USER_ALREADY_EXISTS";
13
14
  ErrorTypes["FAILED_TO_FETCH"] = "FAILED_TO_FETCH";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alore/auth-react-sdk",
3
- "version": "1.1.0-alpha.3",
3
+ "version": "1.1.0-alpha.5",
4
4
  "repository": "https://github.com/0xCarbon/alore-js",
5
5
  "description": "SDK for Alore Auth",
6
6
  "main": "dist/index.js",