Skip to content

Commit 29b07bc

Browse files
committed
chore: improve MFA session handling and add public session APIs
- Add public getAccessToken() and refreshSession() methods to Auth class - refreshSession() validates session and clears SDK state on failure - Replace all rehydrateSession() calls with refreshSession() for consistent error handling; remove dead rehydrateSession() method - Update enableMFA, manageMFA, and all factor management methods to use refreshSession() and pass accessToken in request payloads - Extract clearState() helper from logout() to avoid duplication - Remove authSessionManager getter that exposed internal session manager - Restore MFA_LEVELS.DEFAULT to avoid breaking change - Vue example: track MFA status via reactive ref and reset on logout Made-with: Cursor
1 parent 67b5210 commit 29b07bc

11 files changed

Lines changed: 1137 additions & 401 deletions

File tree

examples/vue-example/package-lock.json

Lines changed: 48 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/vue-example/src/App.vue

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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" />
@@ -65,7 +65,7 @@
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
553553
const loading = ref(false);
554554
const privKey = ref("");
555+
const mfaEnabled = ref(false);
555556
const walletClient = ref<WalletClient | null>(null);
556557
const selectedLoginProvider = ref<AUTH_CONNECTION_TYPE>(AUTH_CONNECTION.GOOGLE);
557558
const 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-
764762
const 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
779781
const 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

Comments
 (0)