11<template >
2- <nav class =" bg-white sticky top-0 z-50 w-full z-20 top-0 start-0 border-gray-200 dark:border-gray-600" >
2+ <nav class =" bg-white sticky w-full z-20 top-0 start-0 border-gray-200 dark:border-gray-600" >
33 <div class =" max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-4" >
44 <a href =" #" class =" flex items-center space-x-3 rtl:space-x-reverse" >
55 <img :src =" `/assets/web3auth.svg`" class =" h-8" alt =" W3A Logo" />
6565 </div >
6666 <div class =" mb-4" >
6767 <Button
68- v-if =" isMFAEnabled() "
68+ v-if =" mfaEnabled "
6969 :class =" ['w-full !h-auto group py-3 rounded-full flex items-center justify-center']"
7070 type =" button"
7171 block
@@ -552,6 +552,7 @@ type EMAIL_FLOW_TYPE = (typeof EMAIL_FLOW)[keyof typeof EMAIL_FLOW];
552552
553553const loading = ref (false );
554554const privKey = ref (" " );
555+ const mfaEnabled = ref (false );
555556const walletClient = ref <WalletClient | null >(null );
556557const selectedLoginProvider = ref <AUTH_CONNECTION_TYPE >(AUTH_CONNECTION .GOOGLE );
557558const login_hint = ref (" " );
@@ -658,6 +659,7 @@ const init = async () => {
658659 console .log (" Login time" , ` ${loginTime }s ` );
659660 }
660661 privKey .value = openloginInstance .value .privKey || (openloginInstance .value .state .walletKey as string );
662+ mfaEnabled .value = openloginInstance .value .state ?.userInfo ?.isMfaEnabled || false ;
661663 await setProvider (privKey .value );
662664 }
663665 loading .value = false ;
@@ -747,6 +749,7 @@ const login = async () => {
747749 console .log (" Login time" , ` ${loginTime }s ` );
748750
749751 privKey .value = openloginInstance .value .privKey || openloginInstance .value .state .walletKey || " " ;
752+ mfaEnabled .value = openloginInstance .value .state ?.userInfo ?.isMfaEnabled || false ;
750753 await setProvider (privKey .value );
751754 }
752755 } catch (error ) {
@@ -756,11 +759,6 @@ const login = async () => {
756759 }
757760};
758761
759- const isMFAEnabled = () => {
760- if (! openloginInstance .value || ! openloginInstance .value .sessionId ) return false ;
761- return openloginInstance .value .state ?.userInfo ?.isMfaEnabled || false ;
762- };
763-
764762const getUserInfo = async () => {
765763 if (! openloginInstance .value ) {
766764 throw new Error (" Openlogin is not available." );
@@ -773,7 +771,11 @@ const enableMFA = async () => {
773771 if (! openloginInstance .value || ! openloginInstance .value .sessionId ) {
774772 throw new Error (" User not logged in" );
775773 }
776- await openloginInstance .value .enableMFA ({});
774+ const result = await openloginInstance .value .enableMFA ({});
775+ console .log (" Enable MFA Result" , result );
776+ if (result ) {
777+ mfaEnabled .value = true ;
778+ }
777779};
778780
779781const manageMFA = async () => {
@@ -817,6 +819,7 @@ const logout = async () => {
817819 }
818820 await openloginInstance .value .logout ();
819821 privKey .value = openloginInstance .value .privKey ;
822+ mfaEnabled .value = false ;
820823 walletClient .value = null ;
821824 if (storageAvailable (" sessionStorage" )) sessionStorage .removeItem (" state" );
822825};
0 commit comments