@alore/auth-react-sdk 1.0.7-alpha → 1.1.0-alpha.2

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/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './utils/AloreAuth';
2
2
  export * from './helpers/crypto';
3
+ export * from './types';
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './utils/AloreAuth';
2
2
  export * from './helpers/crypto';
3
+ export * from './types';
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;
@@ -37,6 +38,7 @@ export interface AuthProviderConfig {
37
38
  socialProviders?: SocialProvider[];
38
39
  enableWalletCreation?: boolean;
39
40
  firebaseCompatible?: boolean;
41
+ allowedEmailDomains?: string | string[];
40
42
  }
41
43
  export interface AuthMachineContext {
42
44
  authProviderConfigs?: AuthProviderConfig;
@@ -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: {
@@ -57,6 +82,9 @@ export class AloreAuth {
57
82
  }),
58
83
  completeRegistration: (context, event) => __awaiter(this, void 0, void 0, function* () {
59
84
  const { email, nickname, passwordHash, device } = event.payload;
85
+ if (!this.services.isEmailAllowed(context, email)) {
86
+ throw new Error('Email domain not allowed');
87
+ }
60
88
  const { firebaseCompatible } = context.authProviderConfigs || {};
61
89
  const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/account-registration${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
62
90
  method: 'POST',
@@ -93,6 +121,9 @@ export class AloreAuth {
93
121
  }),
94
122
  sendConfirmationEmail: (context, event) => __awaiter(this, void 0, void 0, function* () {
95
123
  const { email, nickname, locale } = event.payload;
124
+ if (!this.services.isEmailAllowed(context, email)) {
125
+ throw new Error('Email domain not allowed');
126
+ }
96
127
  const searchParams = new URLSearchParams();
97
128
  const url = '/auth/v1/confirmation-email';
98
129
  if (locale) {
@@ -124,6 +155,9 @@ export class AloreAuth {
124
155
  }),
125
156
  sendCode: (context, event) => __awaiter(this, void 0, void 0, function* () {
126
157
  const { email } = event.payload;
158
+ if (!this.services.isEmailAllowed(context, email)) {
159
+ return { error: 'Email domain not allowed' };
160
+ }
127
161
  const response = yield this.fetchWithProgressiveBackoff(`/reset-password`, {
128
162
  method: 'POST',
129
163
  headers: {
@@ -140,6 +174,9 @@ export class AloreAuth {
140
174
  verifyLogin: (context, event) => __awaiter(this, void 0, void 0, function* () {
141
175
  var _a, _b;
142
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
+ }
143
180
  const { credentialEmail } = context;
144
181
  const searchParams = new URLSearchParams();
145
182
  const url = '/auth/v1/login-verification';
@@ -178,6 +215,9 @@ export class AloreAuth {
178
215
  startRegisterPasskey: (context, event) => __awaiter(this, void 0, void 0, function* () {
179
216
  const { rpDomain } = context.authProviderConfigs || {};
180
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
+ }
181
221
  const startPasskeyRegistrationResponse = yield this.fetchWithProgressiveBackoff('/auth/v1/account-registration-passkey', {
182
222
  method: 'POST',
183
223
  headers: {
@@ -196,6 +236,9 @@ export class AloreAuth {
196
236
  finishRegisterPasskey: (context, event) => __awaiter(this, void 0, void 0, function* () {
197
237
  const { rpDomain } = context.authProviderConfigs || {};
198
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
+ }
199
242
  const response = yield this.fetchWithProgressiveBackoff('/auth/v1/account-registration-passkey-finish', {
200
243
  method: 'POST',
201
244
  headers: {
@@ -219,6 +262,9 @@ export class AloreAuth {
219
262
  var _c;
220
263
  const { rpDomain } = context.authProviderConfigs || {};
221
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
+ }
222
268
  const searchParams = new URLSearchParams();
223
269
  const url = '/auth/v1/login-passkey';
224
270
  if (rpDomain) {
@@ -334,6 +380,9 @@ export class AloreAuth {
334
380
  verifyEmail2fa: (context, event) => __awaiter(this, void 0, void 0, function* () {
335
381
  const { email, passwordHash, secureCode } = event.payload;
336
382
  const { credentialEmail, authProviderConfigs } = context;
383
+ if (!this.services.isEmailAllowed(context, email || credentialEmail)) {
384
+ throw new Error('Email domain not allowed');
385
+ }
337
386
  const { firebaseCompatible } = authProviderConfigs || {};
338
387
  const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/email-2fa-verification${firebaseCompatible ? `?firebaseCompatibleToken=${firebaseCompatible}` : ''}`, {
339
388
  method: 'POST',
@@ -411,6 +460,9 @@ export class AloreAuth {
411
460
  });
412
461
  const data = yield response.json();
413
462
  if (response.ok) {
463
+ if (!this.services.isEmailAllowed(context, data.email)) {
464
+ throw new Error('Email domain not allowed');
465
+ }
414
466
  return {
415
467
  googleOtpCode: data.otpCode,
416
468
  salt: data.salt,
@@ -423,6 +475,9 @@ export class AloreAuth {
423
475
  };
424
476
  }
425
477
  if (response.status === 404) {
478
+ if (!this.services.isEmailAllowed(context, data.email)) {
479
+ throw new Error('Email domain not allowed');
480
+ }
426
481
  return {
427
482
  isNewUser: true,
428
483
  socialProviderRegisterUser: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alore/auth-react-sdk",
3
- "version": "1.0.7-alpha",
3
+ "version": "1.1.0-alpha.2",
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
+ }