# How to: MFA

Let's generate the QR Code to create a new enrollment, using the action Enroll a Factor.

<figure><img src="https://565817280-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmxSvZ04SZeWMqvozlHui%2Fuploads%2FVx6oFSgVNcLUItFhVFVD%2Fimage.png?alt=media&#x26;token=15d22be5-29d3-490b-bdd3-50207d7e3de0" alt=""><figcaption></figcaption></figure>

After we've ran the action we'll recieve back 2 important thing an ID and the QR code in a form of on svg. The plugin will already clean up the QR code for you so all you need to do is to show it to your user, by creating an HTML element on the page and reference the QR code, like so:

<figure><img src="https://565817280-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmxSvZ04SZeWMqvozlHui%2Fuploads%2FJemEnCv0YeKTi9KRLGrt%2Fimage.png?alt=media&#x26;token=53796a7f-a893-460e-9238-e747b80e55a3" alt=""><figcaption></figcaption></figure>

After the User has scanned the QR code and added your app to their Google Authenticator or any other 2FA app, we'll need to verify that this code is valid, using the Create and Verify a Challenge.&#x20;

<figure><img src="https://565817280-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmxSvZ04SZeWMqvozlHui%2Fuploads%2FLGrlaesRAADwHpT85qri%2Fimage.png?alt=media&#x26;token=820efdcb-6cd3-4e34-b8ec-431c7b9e6693" alt=""><figcaption></figcaption></figure>

We need to provide the ID which the plugin will always return by default when MFA is enabled, and the Code which is the 6 number the user sees in his phone.&#x20;

If you'd like to remove the User's 2FA, using the MFA - Unenroll a factor action can be used like so:

<figure><img src="https://565817280-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmxSvZ04SZeWMqvozlHui%2Fuploads%2F5oAa6UsLT6PX1n4elCUp%2Fimage.png?alt=media&#x26;token=8ade20d5-842e-42dc-ac4c-9b8c9c16da23" alt=""><figcaption></figcaption></figure>

Removing the MFA will essentially take place in effect once the user have been logged out and needs to login again, and can be only initiated if the user have confirmed the verified the challenge.&#x20;

So we've done the initial setup let's look at how you can determine during the login process that the user needs to enter MFA. This is done by running the "MFA - Get Authenticator Assurance Level" action.&#x20;

* Authenticator Assurance Level (AAL) is the measure of the strength of an authentication mechanism.
* In Supabase, having an AAL of `aal1` refers to having the 1st factor of authentication such as an email and password or OAuth sign-in while `aal2` refers to the 2nd factor of authentication such as a time-based, one-time-password (TOTP).
* If the user has a verified factor, the `nextLevel` field will return `aal2`, else, it will return `aal1`.

Running this action, the plugin will return both the `currentLevel` and `nextLevel` states, so you can conditionally show groups or run related workflows.&#x20;

Since Supabase.js 3.0.0 you can also do MFA via sms. For that to work you need to enable that in your Supabase dashboard under Authentication

<figure><img src="https://565817280-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmxSvZ04SZeWMqvozlHui%2Fuploads%2Fyl1sRLIZTqkzNDA94O43%2Fimage.png?alt=media&#x26;token=cd75a8d6-1afa-4b71-be22-7927ec5f11da" alt=""><figcaption></figcaption></figure>
