@pubflow/react 0.4.10 → 0.4.13
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.cjs +46 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.esm.js +46 -54
- package/dist/index.esm.js.map +1 -1
- package/dist/types/context/PubflowProvider.d.ts +2 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -254,7 +254,7 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
254
254
|
});
|
|
255
255
|
const apiClient = new core.ApiClient(fullConfig, storage);
|
|
256
256
|
const authService = new core.AuthService(apiClient, storage, fullConfig);
|
|
257
|
-
const twoFactorService = new core.TwoFactorService(apiClient, fullConfig);
|
|
257
|
+
const twoFactorService = new core.TwoFactorService(apiClient, `${fullConfig.authBasePath || '/auth'}/two_factor`);
|
|
258
258
|
// Get current user (non-blocking)
|
|
259
259
|
let user = null;
|
|
260
260
|
let isAuthenticated = false;
|
|
@@ -270,10 +270,21 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
270
270
|
twoFactorMethods: [],
|
|
271
271
|
login: async (credentials) => {
|
|
272
272
|
const result = await authService.login(credentials);
|
|
273
|
-
if (
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
273
|
+
if (result.success && result.user && isMounted) {
|
|
274
|
+
setContextValue(prev => ({
|
|
275
|
+
...prev,
|
|
276
|
+
instances: {
|
|
277
|
+
...prev.instances,
|
|
278
|
+
[instanceConfig.id]: {
|
|
279
|
+
...prev.instances[instanceConfig.id],
|
|
280
|
+
user: result.user,
|
|
281
|
+
isAuthenticated: true,
|
|
282
|
+
isLoading: false
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}));
|
|
286
|
+
}
|
|
287
|
+
else if (result.requires2fa && isMounted) {
|
|
277
288
|
setContextValue(prev => {
|
|
278
289
|
var _a;
|
|
279
290
|
return ({
|
|
@@ -282,30 +293,14 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
282
293
|
...prev.instances,
|
|
283
294
|
[instanceConfig.id]: {
|
|
284
295
|
...prev.instances[instanceConfig.id],
|
|
285
|
-
isLoading: false,
|
|
286
296
|
twoFactorPending: true,
|
|
287
297
|
twoFactorMethods: (_a = result.availableMethods) !== null && _a !== void 0 ? _a : [],
|
|
298
|
+
isLoading: false
|
|
288
299
|
}
|
|
289
300
|
}
|
|
290
301
|
});
|
|
291
302
|
});
|
|
292
303
|
}
|
|
293
|
-
else if (result.success && result.user) {
|
|
294
|
-
setContextValue(prev => ({
|
|
295
|
-
...prev,
|
|
296
|
-
instances: {
|
|
297
|
-
...prev.instances,
|
|
298
|
-
[instanceConfig.id]: {
|
|
299
|
-
...prev.instances[instanceConfig.id],
|
|
300
|
-
user: result.user,
|
|
301
|
-
isAuthenticated: true,
|
|
302
|
-
isLoading: false,
|
|
303
|
-
twoFactorPending: false,
|
|
304
|
-
twoFactorMethods: [],
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}));
|
|
308
|
-
}
|
|
309
304
|
return result;
|
|
310
305
|
},
|
|
311
306
|
logout: async () => {
|
|
@@ -321,7 +316,7 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
321
316
|
isAuthenticated: false,
|
|
322
317
|
isLoading: false,
|
|
323
318
|
twoFactorPending: false,
|
|
324
|
-
twoFactorMethods: []
|
|
319
|
+
twoFactorMethods: []
|
|
325
320
|
}
|
|
326
321
|
}
|
|
327
322
|
}));
|
|
@@ -345,10 +340,12 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
345
340
|
}
|
|
346
341
|
return result;
|
|
347
342
|
},
|
|
343
|
+
startTwoFactor: async (methodId, method) => {
|
|
344
|
+
return twoFactorService.start(methodId, method, 'login');
|
|
345
|
+
},
|
|
348
346
|
verifyTwoFactor: async (methodId, code) => {
|
|
349
347
|
const result = await twoFactorService.verify(methodId, code, 'login');
|
|
350
348
|
if (result.verified && isMounted) {
|
|
351
|
-
// Fetch the now-active user from the server
|
|
352
349
|
const userData = await authService.getCurrentUser();
|
|
353
350
|
setContextValue(prev => ({
|
|
354
351
|
...prev,
|
|
@@ -358,17 +355,15 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
358
355
|
...prev.instances[instanceConfig.id],
|
|
359
356
|
user: userData,
|
|
360
357
|
isAuthenticated: true,
|
|
358
|
+
isLoading: false,
|
|
361
359
|
twoFactorPending: false,
|
|
362
|
-
twoFactorMethods: []
|
|
360
|
+
twoFactorMethods: []
|
|
363
361
|
}
|
|
364
362
|
}
|
|
365
363
|
}));
|
|
366
364
|
}
|
|
367
365
|
return result;
|
|
368
366
|
},
|
|
369
|
-
startTwoFactor: async (methodId, method) => {
|
|
370
|
-
return twoFactorService.start(methodId, method, 'login');
|
|
371
|
-
},
|
|
372
367
|
};
|
|
373
368
|
// Load user asynchronously
|
|
374
369
|
authService.getCurrentUser().then(currentUser => {
|
|
@@ -417,7 +412,7 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
417
412
|
});
|
|
418
413
|
const apiClient = new core.ApiClient(fullConfig, storage);
|
|
419
414
|
const authService = new core.AuthService(apiClient, storage, fullConfig);
|
|
420
|
-
const twoFactorService = new core.TwoFactorService(apiClient, fullConfig);
|
|
415
|
+
const twoFactorService = new core.TwoFactorService(apiClient, `${fullConfig.authBasePath || '/auth'}/two_factor`);
|
|
421
416
|
instancesMap[defaultInstance] = {
|
|
422
417
|
config: fullConfig,
|
|
423
418
|
apiClient,
|
|
@@ -430,9 +425,21 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
430
425
|
twoFactorMethods: [],
|
|
431
426
|
login: async (credentials) => {
|
|
432
427
|
const result = await authService.login(credentials);
|
|
433
|
-
if (
|
|
434
|
-
|
|
435
|
-
|
|
428
|
+
if (result.success && result.user && isMounted) {
|
|
429
|
+
setContextValue(prev => ({
|
|
430
|
+
...prev,
|
|
431
|
+
instances: {
|
|
432
|
+
...prev.instances,
|
|
433
|
+
[defaultInstance]: {
|
|
434
|
+
...prev.instances[defaultInstance],
|
|
435
|
+
user: result.user,
|
|
436
|
+
isAuthenticated: true,
|
|
437
|
+
isLoading: false
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}));
|
|
441
|
+
}
|
|
442
|
+
else if (result.requires2fa && isMounted) {
|
|
436
443
|
setContextValue(prev => {
|
|
437
444
|
var _a;
|
|
438
445
|
return ({
|
|
@@ -441,30 +448,14 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
441
448
|
...prev.instances,
|
|
442
449
|
[defaultInstance]: {
|
|
443
450
|
...prev.instances[defaultInstance],
|
|
444
|
-
isLoading: false,
|
|
445
451
|
twoFactorPending: true,
|
|
446
452
|
twoFactorMethods: (_a = result.availableMethods) !== null && _a !== void 0 ? _a : [],
|
|
453
|
+
isLoading: false
|
|
447
454
|
}
|
|
448
455
|
}
|
|
449
456
|
});
|
|
450
457
|
});
|
|
451
458
|
}
|
|
452
|
-
else if (result.success && result.user) {
|
|
453
|
-
setContextValue(prev => ({
|
|
454
|
-
...prev,
|
|
455
|
-
instances: {
|
|
456
|
-
...prev.instances,
|
|
457
|
-
[defaultInstance]: {
|
|
458
|
-
...prev.instances[defaultInstance],
|
|
459
|
-
user: result.user,
|
|
460
|
-
isAuthenticated: true,
|
|
461
|
-
isLoading: false,
|
|
462
|
-
twoFactorPending: false,
|
|
463
|
-
twoFactorMethods: [],
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}));
|
|
467
|
-
}
|
|
468
459
|
return result;
|
|
469
460
|
},
|
|
470
461
|
logout: async () => {
|
|
@@ -480,7 +471,7 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
480
471
|
isAuthenticated: false,
|
|
481
472
|
isLoading: false,
|
|
482
473
|
twoFactorPending: false,
|
|
483
|
-
twoFactorMethods: []
|
|
474
|
+
twoFactorMethods: []
|
|
484
475
|
}
|
|
485
476
|
}
|
|
486
477
|
}));
|
|
@@ -504,6 +495,9 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
504
495
|
}
|
|
505
496
|
return result;
|
|
506
497
|
},
|
|
498
|
+
startTwoFactor: async (methodId, method) => {
|
|
499
|
+
return twoFactorService.start(methodId, method, 'login');
|
|
500
|
+
},
|
|
507
501
|
verifyTwoFactor: async (methodId, code) => {
|
|
508
502
|
const result = await twoFactorService.verify(methodId, code, 'login');
|
|
509
503
|
if (result.verified && isMounted) {
|
|
@@ -516,17 +510,15 @@ function PubflowProvider({ children, config, instances, defaultInstance = 'defau
|
|
|
516
510
|
...prev.instances[defaultInstance],
|
|
517
511
|
user: userData,
|
|
518
512
|
isAuthenticated: true,
|
|
513
|
+
isLoading: false,
|
|
519
514
|
twoFactorPending: false,
|
|
520
|
-
twoFactorMethods: []
|
|
515
|
+
twoFactorMethods: []
|
|
521
516
|
}
|
|
522
517
|
}
|
|
523
518
|
}));
|
|
524
519
|
}
|
|
525
520
|
return result;
|
|
526
521
|
},
|
|
527
|
-
startTwoFactor: async (methodId, method) => {
|
|
528
|
-
return twoFactorService.start(methodId, method, 'login');
|
|
529
|
-
},
|
|
530
522
|
};
|
|
531
523
|
// Load user asynchronously
|
|
532
524
|
authService.getCurrentUser().then(currentUser => {
|