Skip to content

Commit 0007cfc

Browse files
Merge pull request #2037 from Web3Auth/feat/manage-mfa
add support to manage mfa with web3auth
2 parents a5ed0d3 + 9c3e769 commit 0007cfc

File tree

40 files changed

+319
-137
lines changed

40 files changed

+319
-137
lines changed

demo/vite-react-app/src/components/Main.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const Main = () => {
1818
switchChain,
1919
showWalletConnectScanner,
2020
enableMFA,
21+
manageMFA,
2122
} = useWeb3Auth();
2223

2324
const loggedInView = (
@@ -43,6 +44,9 @@ const Main = () => {
4344
<button onClick={enableMFA} className={styles.card}>
4445
Enable MFA
4546
</button>
47+
<button onClick={manageMFA} className={styles.card}>
48+
Manage MFA
49+
</button>
4650
{web3Auth?.connectedAdapterName === WALLET_ADAPTERS.AUTH && (
4751
<button onClick={signTransaction} className={styles.card}>
4852
Sign Transaction

demo/vite-react-app/src/services/web3auth.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface IWeb3AuthContext {
2727
showWalletConnectScanner: () => Promise<void>;
2828
showWalletUi: () => Promise<void>;
2929
enableMFA: () => Promise<void>;
30+
manageMFA: () => Promise<void>;
3031
}
3132

3233
export const Web3AuthContext = createContext<IWeb3AuthContext>({
@@ -47,6 +48,7 @@ export const Web3AuthContext = createContext<IWeb3AuthContext>({
4748
showWalletConnectScanner: async () => {},
4849
showWalletUi: async () => {},
4950
enableMFA: async () => {},
51+
manageMFA: async () => {},
5052
});
5153

5254
export function useWeb3Auth(): IWeb3AuthContext {
@@ -226,6 +228,15 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
226228
await web3Auth.enableMFA();
227229
};
228230

231+
const manageMFA = async () => {
232+
if (!web3Auth) {
233+
console.log("web3auth not initialized yet");
234+
uiConsole("web3auth not initialized yet");
235+
return;
236+
}
237+
await web3Auth.manageMFA();
238+
};
239+
229240
const addChain = async () => {
230241
if (!provider) {
231242
uiConsole("provider not initialized yet");
@@ -343,6 +354,7 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
343354
switchChain,
344355
showWalletConnectScanner,
345356
enableMFA,
357+
manageMFA,
346358
showWalletUi,
347359
};
348360
return <Web3AuthContext.Provider value={contextProvider}>{children}</Web3AuthContext.Provider>;

0 commit comments

Comments
 (0)