MCPcopy Create free account
hub / github.com/Web3Auth/Auth / enableMFA

Method enableMFA

src/core/auth.ts:276–312  ·  view source on GitHub ↗
(params: Partial<LoginParams>)

Source from the content-addressed store, hash-verified

274 }
275
276 async enableMFA(params: Partial<LoginParams>): Promise<boolean> {
277 if (!this.sessionId) throw LoginError.userNotLoggedIn();
278 await this.refreshSession();
279
280 if (this.state.userInfo.isMfaEnabled) throw LoginError.mfaAlreadyEnabled();
281 const dataObject: AuthRequestPayload = {
282 actionType: AUTH_ACTIONS.ENABLE_MFA,
283 options: { ...this.options, sdkMode: SDK_MODE.DEFAULT },
284 params: {
285 ...params,
286 authConnection: this.state.userInfo.authConnection,
287 authConnectionId: this.state.userInfo.authConnectionId,
288 groupedAuthConnectionId: this.state.userInfo.groupedAuthConnectionId,
289 extraLoginOptions: {
290 login_hint: this.state.userInfo.userId,
291 },
292 mfaLevel: "mandatory",
293 },
294 sessionId: this.sessionId,
295 accessToken: await this.getAccessToken(),
296 };
297
298 const result = await this.authHandler(`${this.baseUrl}/start`, dataObject, POPUP_TIMEOUT);
299 if (!result) return false;
300 if (isAuthFlowError(result)) {
301 this.dappState = result.state;
302 throw LoginError.loginFailed(result.error);
303 }
304 await this.sessionManager.setTokens({
305 sessionId: add0x(result.sessionId),
306 accessToken: result.accessToken,
307 refreshToken: result.refreshToken,
308 idToken: result.idToken,
309 });
310 await this.refreshSession();
311 return Boolean(this.state.userInfo?.isMfaEnabled);
312 }
313
314 async manageMFA(params: Partial<LoginParams>): Promise<void> {
315 if (!this.sessionId) throw LoginError.userNotLoggedIn();

Callers

nothing calls this directly

Calls 7

refreshSessionMethod · 0.95
getAccessTokenMethod · 0.95
authHandlerMethod · 0.95
isAuthFlowErrorFunction · 0.90
userNotLoggedInMethod · 0.80
mfaAlreadyEnabledMethod · 0.80
loginFailedMethod · 0.80

Tested by

no test coverage detected