# Workaround for MFA error when using getAccessTokenSilently with React

**URL:** <https://community.auth0.com/t/workaround-for-mfa-error-when-using-getaccesstokensilently-with-react/104839>\
**Category:** Get Help\
**Tags:** sdks-quickstarts, auth0-react\
**Created:** [April 17, 2023, 4:38am UTC](https://community.auth0.com/t/workaround-for-mfa-error-when-using-getaccesstokensilently-with-react/104839 "2023-04-17T04:38:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zachary.willard](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/zachary.willard/32/38837_2.png) [@zachary.willard](https://community.auth0.com/u/zachary.willard)\
**Post date:** [April 17, 2023, 4:38am UTC](https://community.auth0.com/t/workaround-for-mfa-error-when-using-getaccesstokensilently-with-react/104839/1 "2023-04-17T04:38:08Z")

</div>

Hi,

When using getAccessTokenSilently from the `@auth0/auth0-react` sdk I encountered frequent 403 errors with the error `Type: Failed Silent Auth; Description: Multifactor authentication required`

MFA is required but I also needed to be able to get an access token to call APIs, without prompting the user a second time after they already had authenticated with MFA previously. I had some trouble that took me several hours to figure out and I wanted to post my findings since current threads on this topic were closed, and I couldn’t find help in the Auth0 docs, I hope I can save someone else the trouble.  
In our case we were using Refresh tokens as well. The solution below worked for me:

This is a working Auth0 Action similar to the same rule (which appears to be preferred over Rules)

1. Add an Auth0 Action in the Auth0 Management panel
2. use this code:

```auto
exports.onExecutePostLogin = async (event, api) => {
  if (event.client.name !== <your apps client name>) {
    return;
  }

  const isRefreshTokenProtocol =
    event?.transaction?.protocol === "oauth2-refresh-token";
  let authMethods = [];
  if (event.authentication && Array.isArray(event.authentication.methods)) {
    authMethods = event.authentication.methods;
  }
  const isMFAAuthenticated = Boolean(
    authMethods.find((method) => method.name === "mfa")
  );

  if (isMFAAuthenticated || isRefreshTokenProtocol) {
    api.multifactor.enable("none");
  }
};

```

---

<div class="post-metadata">

**Author:** ![SaqibHussain](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/saqibhussain/32/42924_2.png) [@SaqibHussain](https://community.auth0.com/u/SaqibHussain)\
**Post date:** [April 25, 2023, 10:48pm UTC](https://community.auth0.com/t/workaround-for-mfa-error-when-using-getaccesstokensilently-with-react/104839/2 "2023-04-25T22:48:43Z")

</div>

Hi @zachary.willard

Many thanks for posting your findings here, it is much appreciated.

Warm regards.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [April 26, 2023, 9:16am UTC](https://community.auth0.com/t/workaround-for-mfa-error-when-using-getaccesstokensilently-with-react/104839/3 "2023-04-26T09:16:14Z")

</div>

Thank you @zachary.willard ! For those visiting this thread **the solution is posted in the first post in the thread**. Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [May 10, 2023, 9:16am UTC](https://community.auth0.com/t/workaround-for-mfa-error-when-using-getaccesstokensilently-with-react/104839/4 "2023-05-10T09:16:21Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
