I’m building E2E tests with Playwright and want to cover the login flow with Email OTP MFA.
Is it possible to set a static/mock Email OTP code for a specific test user from the Auth0 Dashboard? Or is there any other way to handle this situation?
Would appreciate hearing how others have handled this.
Thanks!
Hi @anndy25
Welcome to the Auth0 Community!
I understand that you are looking to set a static or mock Email OTP code for a specific test user in the Dashboard for your E2E test with Playwright.
While Auth0 does not provide a Dashboard feature to set a static Email OTP code for test users, you can implement a workaround to complete the test.
Recommended approach
It is possible to configure a custom email provider and use a test email service that allows you to programmatically retrieve sent emails and extract the OTP code. This way, your Playwright tests can:
- Trigger the Email OTP flow with a test email address.
- Query the test email service’s API to retrieve the most recent email.
- Extract the OTP code from the email body.
- Use that code to complete the MFA challenge in your test.
Alternative for bypassing MFA for test users using Auth0 Actions
If you just want to test your application’s behavior after login without worrying about intercepting emails every time, you can conditionally disable the MFA requirement for your test accounts:
-
Create a Login Action in the Auth0 Dashboard;
-
Add logic that checks if the logging-in user is your specific test user (e.g., event.user.email === 'playwright-test@yourdomain.com');
-
If it’s the test user, simply omit the api.multifactor.enable(...) call;
-
This allows your test user to log in seamlessly with just a username and password, while real users still get the MFA challenge;
Hope this helped you achieve the desired flow for testing!
Have a great one,
Gerald