@pubflow/react 0.4.7 → 0.4.8
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 +22 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.esm.js +22 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/types/hooks/useTwoFactor.d.ts +8 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1627,18 +1627,21 @@ interface UseTwoFactorResult {
|
|
|
1627
1627
|
systemEnabled: boolean;
|
|
1628
1628
|
/** Available methods on the server (e.g. ['email']) */
|
|
1629
1629
|
availableMethods: string[];
|
|
1630
|
-
/** User's configured 2FA methods */
|
|
1630
|
+
/** User's configured 2FA methods (status = active only) */
|
|
1631
1631
|
methods: TwoFactorMethod[];
|
|
1632
1632
|
isLoading: boolean;
|
|
1633
1633
|
error: string | null;
|
|
1634
1634
|
/** Load system info and user methods */
|
|
1635
1635
|
refresh: () => Promise<void>;
|
|
1636
1636
|
/**
|
|
1637
|
-
*
|
|
1638
|
-
*
|
|
1639
|
-
* @param identifier email address or phone number
|
|
1637
|
+
* Step 1 of setup: register method + send verification code.
|
|
1638
|
+
* Returns { success, method_id, status: 'pending_setup', ... }
|
|
1640
1639
|
*/
|
|
1641
1640
|
setup: (method: string, identifier: string) => Promise<TwoFactorSetupResult>;
|
|
1641
|
+
/**
|
|
1642
|
+
* Step 2 of setup: confirm the code received → activates the method.
|
|
1643
|
+
*/
|
|
1644
|
+
confirmSetup: (methodId: string, method: string, code: string) => Promise<TwoFactorVerifyResult>;
|
|
1642
1645
|
/**
|
|
1643
1646
|
* Enable or disable 2FA for the user.
|
|
1644
1647
|
* When disabling with existing methods a verification code is required.
|
package/dist/index.esm.js
CHANGED
|
@@ -10142,6 +10142,27 @@ function useTwoFactor(instanceId) {
|
|
|
10142
10142
|
setIsLoading(false);
|
|
10143
10143
|
}
|
|
10144
10144
|
}, [instance, refresh]);
|
|
10145
|
+
const confirmSetup = useCallback(async (methodId, method, code) => {
|
|
10146
|
+
if (!instance)
|
|
10147
|
+
return { success: false, verified: false, error: 'Pubflow not initialized' };
|
|
10148
|
+
setIsLoading(true);
|
|
10149
|
+
setError(null);
|
|
10150
|
+
try {
|
|
10151
|
+
// action='setup' activates a pending_setup method in the DB
|
|
10152
|
+
const result = await instance.twoFactorService.verify(methodId, code, 'setup');
|
|
10153
|
+
if (result.verified)
|
|
10154
|
+
await refresh();
|
|
10155
|
+
return result;
|
|
10156
|
+
}
|
|
10157
|
+
catch (e) {
|
|
10158
|
+
const msg = (e === null || e === void 0 ? void 0 : e.message) || 'Confirmation failed';
|
|
10159
|
+
setError(msg);
|
|
10160
|
+
return { success: false, verified: false, error: msg };
|
|
10161
|
+
}
|
|
10162
|
+
finally {
|
|
10163
|
+
setIsLoading(false);
|
|
10164
|
+
}
|
|
10165
|
+
}, [instance, refresh]);
|
|
10145
10166
|
return {
|
|
10146
10167
|
systemEnabled,
|
|
10147
10168
|
availableMethods,
|
|
@@ -10150,6 +10171,7 @@ function useTwoFactor(instanceId) {
|
|
|
10150
10171
|
error,
|
|
10151
10172
|
refresh,
|
|
10152
10173
|
setup,
|
|
10174
|
+
confirmSetup,
|
|
10153
10175
|
toggle,
|
|
10154
10176
|
removeMethod,
|
|
10155
10177
|
};
|