Skip to content

Instantly share code, notes, and snippets.

@ckenst
Created December 5, 2025 23:19
Show Gist options
  • Select an option

  • Save ckenst/486f33eef02084799bb3199dede62ca9 to your computer and use it in GitHub Desktop.

Select an option

Save ckenst/486f33eef02084799bb3199dede62ca9 to your computer and use it in GitHub Desktop.
Mailinator SMS OTP login demo
const { test, expect } = require(@playwright/test’);
const axios = require(‘axios’);
test(‘Login using OTP code via SMS’, async ({ page }) => {
const phoneNumber = ‘15555555555’; // Replace with a Mailinator test phone number
// Navigate to the login page and initiate login
await page.goto(‘https://yourapp.com/login’);
await page.fill(#phone’, phoneNumber);
await page.click(‘button[type=”submit”]);
// Wait for the OTP SMS to arrive
const apiToken = ‘YOUR_MAILINATOR_API_TOKEN’;
const smsResponse = await axios.get(`https://api.mailinator.com/api/v2/domains/private/inboxes/${phoneNumber}`, {
headers: { ‘Authorization’: apiToken }
});
const messages = smsResponse.data.msgs;
const otpMessage = messages.find(msg => msg.subject.includes(‘Your OTP Code’));
// Fetch the full message content
const messageResponse = await axios.get(`https://api.mailinator.com/api/v2/domains/private/messages/${otpMessage.id}`, {
headers: { ‘Authorization’: apiToken }
});
const otpCodeMatch = messageResponse.data.parts[0].body.match(/\d{6}/);
const otpCode = otpCodeMatch ? otpCodeMatch[0] : null;
// Enter the OTP and complete login
await page.fill(#otp’, otpCode);
await page.click(‘button[type=”submit”]);
// Verify successful login
await expect(page).toHaveURL(‘https://yourapp.com/dashboard’);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment