@alore/auth-react-sdk 1.0.6-alpha → 1.1.0-alpha.1

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 CHANGED
@@ -20,6 +20,7 @@ export type KeyDerivationFunction = 'argon2d' | 'pbkdf2';
20
20
  * @property logoUrl - Optional string for logo URL.
21
21
  * @property socialProviders - Optional social login providers.
22
22
  * @property enableWalletCreation - Optional boolean to enable wallet creation.
23
+ * @property allowedEmailDomains - Optional allowed email domain(s). If provided, authentication will only allow emails from these domains. Accepts a single string (e.g., 'bealore.com' or '@bealore.com') or an array of strings.
23
24
  */
24
25
  export interface AuthProviderConfig {
25
26
  rpDomain?: string;
@@ -36,12 +37,9 @@ export interface AuthProviderConfig {
36
37
  logoUrl?: string;
37
38
  socialProviders?: SocialProvider[];
38
39
  enableWalletCreation?: boolean;
39
- firebaseOptions?: FirebaseOptions;
40
- }
41
- type FirebaseOptions = {
42
40
  firebaseCompatible?: boolean;
43
- firebaseServiceAccountEmail?: string;
44
- };
41
+ allowedEmailDomains?: string | string[];
42
+ }
45
43
  export interface AuthMachineContext {
46
44
  authProviderConfigs?: AuthProviderConfig;
47
45
  salt?: string;
@@ -5,6 +5,7 @@ export declare class AloreAuth {
5
5
  protected readonly clientId: string;
6
6
  constructor(clientId: string, aloreBaseUrl?: string, config?: AuthProviderConfig);
7
7
  services: {
8
+ isEmailAllowed: (context: AuthMachineContext, email?: string | null) => boolean;
8
9
  healthCheck: () => Promise<{
9
10
  data: boolean;
10
11
  }>;
@@ -13,6 +13,28 @@ const DEFAULT_URL = 'https://alpha-api.bealore.com/v1';
13
13
  export class AloreAuth {
14
14
  constructor(clientId, aloreBaseUrl, config) {
15
15
  this.services = {
16
+ // Utility to check if an email is allowed based on allowedEmailDomains config
17
+ isEmailAllowed: (context, email) => {
18
+ var _a;
19
+ const allowedConf = (_a = context.authProviderConfigs) === null || _a === void 0 ? void 0 : _a.allowedEmailDomains;
20
+ const allowedList =
21
+ // eslint-disable-next-line no-nested-ternary
22
+ typeof allowedConf === 'string'
23
+ ? [allowedConf]
24
+ : Array.isArray(allowedConf)
25
+ ? allowedConf
26
+ : [];
27
+ if (allowedList.length === 0)
28
+ return true;
29
+ if (!email)
30
+ return false;
31
+ const domain = (email.split('@')[1] || '').toLowerCase();
32
+ // Allow items like '@bealore.com' or 'bealore.com'
33
+ return allowedList.some((d) => {
34
+ const normalized = d.startsWith('@') ? d.slice(1) : d;
35
+ return domain === normalized.toLowerCase();
36
+ });
37
+ },
16
38
  healthCheck: () => __awaiter(this, void 0, void 0, function* () {
17
39
  try {
18
40
  yield this.verifyBackendStatus();
@@ -25,6 +47,9 @@ export class AloreAuth {
25
47
  // Email and password flow
26
48
  retrieveSalt: (context, event) => __awaiter(this, void 0, void 0, function* () {
27
49
  const { email } = event.payload;
50
+ if (!this.services.isEmailAllowed(context, email)) {
51
+ throw new Error('Email domain not allowed');
52
+ }
28
53
  const { credentialEmail } = context;
29
54
  const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/salt/${email || credentialEmail}`, {
30
55
  headers: {
@@ -56,10 +81,12 @@ export class AloreAuth {
56
81
  throw new Error((data === null || data === void 0 ? void 0 : data.message) || (data === null || data === void 0 ? void 0 : data.error) || data);
57
82
  }),
58
83
  completeRegistration: (context, event) => __awaiter(this, void 0, void 0, function* () {
59
- var _a;
60
84
  const { email, nickname, passwordHash, device } = event.payload;
61
- const { firebaseCompatible, firebaseServiceAccountEmail } = ((_a = context.authProviderConfigs) === null || _a === void 0 ? void 0 : _a.firebaseOptions) || {};
62
- const response = yield this.fetchWithProgressiveBackoff('/auth/v1/account-registration', {
85
+ if (!this.services.isEmailAllowed(context, email)) {
86
+ throw new Error('Email domain not allowed');
87
+ }
88
+ const { firebaseCompatible } = context.authProviderConfigs || {};
89
+ const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/account-registration${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
63
90
  method: 'POST',
64
91
  headers: {
65
92
  'Content-Type': 'application/json',
@@ -69,10 +96,6 @@ export class AloreAuth {
69
96
  nickname,
70
97
  passwordHash,
71
98
  device,
72
- firebaseOptions: {
73
- firebaseCompatible,
74
- firebaseServiceAccountEmail,
75
- },
76
99
  }),
77
100
  });
78
101
  const data = yield response.json();
@@ -98,6 +121,9 @@ export class AloreAuth {
98
121
  }),
99
122
  sendConfirmationEmail: (context, event) => __awaiter(this, void 0, void 0, function* () {
100
123
  const { email, nickname, locale } = event.payload;
124
+ if (!this.services.isEmailAllowed(context, email)) {
125
+ throw new Error('Email domain not allowed');
126
+ }
101
127
  const searchParams = new URLSearchParams();
102
128
  const url = '/auth/v1/confirmation-email';
103
129
  if (locale) {
@@ -129,6 +155,9 @@ export class AloreAuth {
129
155
  }),
130
156
  sendCode: (context, event) => __awaiter(this, void 0, void 0, function* () {
131
157
  const { email } = event.payload;
158
+ if (!this.services.isEmailAllowed(context, email)) {
159
+ return { error: 'Email domain not allowed' };
160
+ }
132
161
  const response = yield this.fetchWithProgressiveBackoff(`/reset-password`, {
133
162
  method: 'POST',
134
163
  headers: {
@@ -143,8 +172,11 @@ export class AloreAuth {
143
172
  return {};
144
173
  }),
145
174
  verifyLogin: (context, event) => __awaiter(this, void 0, void 0, function* () {
146
- var _b, _c;
175
+ var _a, _b;
147
176
  const { email, passwordHash, device, locale } = event.payload;
177
+ if (!this.services.isEmailAllowed(context, email || context.credentialEmail)) {
178
+ throw new Error('Email domain not allowed');
179
+ }
148
180
  const { credentialEmail } = context;
149
181
  const searchParams = new URLSearchParams();
150
182
  const url = '/auth/v1/login-verification';
@@ -170,7 +202,7 @@ export class AloreAuth {
170
202
  if (response.status === 403) {
171
203
  return { active2fa: data };
172
204
  }
173
- if (((_b = data === null || data === void 0 ? void 0 : data.error) === null || _b === void 0 ? void 0 : _b.includes('2FA')) || ((_c = data === null || data === void 0 ? void 0 : data.error) === null || _c === void 0 ? void 0 : _c.includes('device'))) {
205
+ 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'))) {
174
206
  return { error: data === null || data === void 0 ? void 0 : data.error };
175
207
  }
176
208
  throw new Error((data === null || data === void 0 ? void 0 : data.message) || (data === null || data === void 0 ? void 0 : data.error) || data);
@@ -183,6 +215,9 @@ export class AloreAuth {
183
215
  startRegisterPasskey: (context, event) => __awaiter(this, void 0, void 0, function* () {
184
216
  const { rpDomain } = context.authProviderConfigs || {};
185
217
  const { email, nickname, device } = event.payload || context.registerUser;
218
+ if (email && !this.services.isEmailAllowed(context, email)) {
219
+ throw new Error('Email domain not allowed');
220
+ }
186
221
  const startPasskeyRegistrationResponse = yield this.fetchWithProgressiveBackoff('/auth/v1/account-registration-passkey', {
187
222
  method: 'POST',
188
223
  headers: {
@@ -201,6 +236,9 @@ export class AloreAuth {
201
236
  finishRegisterPasskey: (context, event) => __awaiter(this, void 0, void 0, function* () {
202
237
  const { rpDomain } = context.authProviderConfigs || {};
203
238
  const { email, nickname, device, passkeyRegistration } = event.payload || {};
239
+ if (email && !this.services.isEmailAllowed(context, email)) {
240
+ throw new Error('Email domain not allowed');
241
+ }
204
242
  const response = yield this.fetchWithProgressiveBackoff('/auth/v1/account-registration-passkey-finish', {
205
243
  method: 'POST',
206
244
  headers: {
@@ -221,9 +259,12 @@ export class AloreAuth {
221
259
  }),
222
260
  // Passkey login flow
223
261
  startPasskeyAuth: (context, event) => __awaiter(this, void 0, void 0, function* () {
224
- var _d;
262
+ var _c;
225
263
  const { rpDomain } = context.authProviderConfigs || {};
226
- const email = (_d = event.payload) === null || _d === void 0 ? void 0 : _d.email;
264
+ const email = (_c = event.payload) === null || _c === void 0 ? void 0 : _c.email;
265
+ if (email && !this.services.isEmailAllowed(context, email)) {
266
+ throw new Error('Email domain not allowed');
267
+ }
227
268
  const searchParams = new URLSearchParams();
228
269
  const url = '/auth/v1/login-passkey';
229
270
  if (rpDomain) {
@@ -240,9 +281,9 @@ export class AloreAuth {
240
281
  throw new Error(data.message || data.error || data);
241
282
  }),
242
283
  finishPasskeyAuth: (context, event) => __awaiter(this, void 0, void 0, function* () {
243
- const { rpDomain, firebaseOptions } = context.authProviderConfigs || {};
284
+ const { rpDomain, firebaseCompatible } = context.authProviderConfigs || {};
244
285
  const { passkeyAuth } = event.payload;
245
- const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/login-passkey-finish`, {
286
+ const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/login-passkey-finish${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
246
287
  method: 'POST',
247
288
  headers: {
248
289
  'Content-Type': 'application/json',
@@ -251,7 +292,6 @@ export class AloreAuth {
251
292
  passkeyAuth,
252
293
  sessionId: context.sessionId,
253
294
  rpOrigin: rpDomain,
254
- firebaseOptions,
255
295
  }),
256
296
  });
257
297
  const data = yield response.json();
@@ -340,15 +380,17 @@ export class AloreAuth {
340
380
  verifyEmail2fa: (context, event) => __awaiter(this, void 0, void 0, function* () {
341
381
  const { email, passwordHash, secureCode } = event.payload;
342
382
  const { credentialEmail, authProviderConfigs } = context;
343
- const { firebaseOptions } = authProviderConfigs || {};
344
- const response = yield this.fetchWithProgressiveBackoff('/auth/v1/email-2fa-verification', {
383
+ if (!this.services.isEmailAllowed(context, email || credentialEmail)) {
384
+ throw new Error('Email domain not allowed');
385
+ }
386
+ const { firebaseCompatible } = authProviderConfigs || {};
387
+ const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/email-2fa-verification${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
345
388
  method: 'POST',
346
389
  body: JSON.stringify({
347
390
  email: email || credentialEmail,
348
391
  passwordHash,
349
392
  emailCode: secureCode,
350
393
  sessionId: context.sessionId,
351
- firebaseOptions,
352
394
  }),
353
395
  headers: {
354
396
  'Content-Type': 'application/json',
@@ -405,8 +447,8 @@ export class AloreAuth {
405
447
  googleLogin: (context, event) => __awaiter(this, void 0, void 0, function* () {
406
448
  const { accessToken, providerName } = event.payload;
407
449
  const { authProviderConfigs } = context;
408
- const { firebaseOptions } = authProviderConfigs || {};
409
- const response = yield this.fetchWithProgressiveBackoff('/auth/v1/google-login', {
450
+ const { firebaseCompatible } = authProviderConfigs || {};
451
+ const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/google-login${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
410
452
  method: 'POST',
411
453
  headers: {
412
454
  'Content-Type': 'application/json',
@@ -414,11 +456,13 @@ export class AloreAuth {
414
456
  body: JSON.stringify({
415
457
  accessToken,
416
458
  provider: providerName,
417
- firebaseOptions,
418
459
  }),
419
460
  });
420
461
  const data = yield response.json();
421
462
  if (response.ok) {
463
+ if (!this.services.isEmailAllowed(context, data.email)) {
464
+ throw new Error('Email domain not allowed');
465
+ }
422
466
  return {
423
467
  googleOtpCode: data.otpCode,
424
468
  salt: data.salt,
@@ -431,6 +475,9 @@ export class AloreAuth {
431
475
  };
432
476
  }
433
477
  if (response.status === 404) {
478
+ if (!this.services.isEmailAllowed(context, data.email)) {
479
+ throw new Error('Email domain not allowed');
480
+ }
434
481
  return {
435
482
  isNewUser: true,
436
483
  socialProviderRegisterUser: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alore/auth-react-sdk",
3
- "version": "1.0.6-alpha",
3
+ "version": "1.1.0-alpha.1",
4
4
  "repository": "https://github.com/0xCarbon/alore-js",
5
5
  "description": "SDK for Alore Auth",
6
6
  "main": "dist/index.js",
@@ -14,10 +14,6 @@
14
14
  "default": "./dist/index.js"
15
15
  }
16
16
  },
17
- "scripts": {
18
- "prepare": "pnpm build",
19
- "build": "rm -rf dist/* && tsc"
20
- },
21
17
  "author": "0xCarbon",
22
18
  "license": "LGPL-2.1-only",
23
19
  "engines": {
@@ -36,5 +32,8 @@
36
32
  "@types/node": "20.4.8",
37
33
  "typescript": "5.4.5"
38
34
  },
39
- "packageManager": "pnpm@8.15.7+sha512.c85cd21b6da10332156b1ca2aa79c0a61ee7ad2eb0453b88ab299289e9e8ca93e6091232b25c07cbf61f6df77128d9c849e5c9ac6e44854dbd211c49f3a67adc"
40
- }
35
+ "packageManager": "pnpm@8.15.9",
36
+ "scripts": {
37
+ "build": "rm -rf dist/* && tsc"
38
+ }
39
+ }