Scroll AI Now

Agent skill

Login flows

Common login automation patterns for web apps using Playwright. A copy‑ready agent skill by andrewyng, with the full text, MIT license and how to use it.

By andrewyng · andrewyng/context‑hub · MIT License · ★ 14,000 · 108 lines

New to this? An agent skill is a file of instructions your AI assistant follows for one job. The text above is written for the assistant. How to use a skill

What it does

Login flows is an agent workflow skill from andrewyng/context‑hub, a GitHub repo with 13,997 stars.
In short, it changes how your assistant plans and carries out multi step work.
The file is 108 lines long and is set out in parts such as “Basic Username/Password Login”, “OAuth / SSO Login”, “Persisting Auth State (storageState)” and “MFA / 2FA Handling”.
It has 5 code examples your assistant can follow.

When to use it

Reach for it when a task has several steps and you want the assistant to follow a routine.
Everything it needs is in this one file.
It does not ask for special tools.

Safety check

Our checker read all 108 lines before we listed it.
It found no attack techniques, no hidden text and no steps that switch off your assistant's safety or send your data away.
It flagged nothing else to watch for.
The text links to no outside sites.
It is shared under the MIT license.
Still read it before you use it, like any instructions you give your AI.

Open in the appOriginal on GitHub

What is inside

How to use it

Read the full guide to using an agent skill

Want your own? How to write an agent skill that works

The full skill

---
name: login-flows
description: Common login automation patterns for web apps using Playwright
metadata:
  updated-on: "2026-02-01"
  source: community
  tags: "browser,automation,playwright,login,testing"
---

# Login Flow Patterns for Playwright

Reusable patterns for automating login flows in end-to-end tests.

## Basic Username/Password Login

```typescript
import { Page } from '@playwright/test';

async function login(page: Page, username: string, password: string) {
  await page.goto('/login');
  await page.fill('[name="username"]', username);
  await page.fill('[name="password"]', password);
  await page.click('button[type="submit"]');
  await page.waitForURL('/dashboard');
}
```

## OAuth / SSO Login

For OAuth flows that redirect to an external provider:

```typescript
async function loginWithOAuth(page: Page) {
  await page.goto('/login');
  await page.click('text=Sign in with Google');

  // Handle the OAuth popup or redirect
  await page.fill('input[type="email"]', process.env.TEST_EMAIL!);
  await page.click('text=Next');
  await page.fill('input[type="password"]', process.env.TEST_PASSWORD!);
  await page.click('text=Next');

  // Wait for redirect back to app
  await page.waitForURL('**/dashboard');
}
```

## Persisting Auth State (storageState)

Avoid logging in before every test by saving and reusing browser state:

```typescript
// global-setup.ts — runs once before all tests
import { chromium } from '@playwright/test';

async function globalSetup() {
  const browser = await chromium.launch();
  const page = await browser.newPage();

  await page.goto('/login');
  await page.fill('[name="username"]', 'testuser');
  await page.fill('[name="password"]', 'testpass');
  await page.click('button[type="submit"]');
  await page.waitForURL('/dashboard');

  // Save signed-in state
  await page.context().storageState({ path: './auth.json' });
  await browser.close();
}

export default globalSetup;
```

Then in `playwright.config.ts`:

```typescript
export default defineConfig({
  globalSetup: './global-setup.ts',
  use: {
    storageState: './auth.json',
  },
});
```

## MFA / 2FA Handling

For test environments with TOTP-based 2FA:

```typescript
import { authenticator } from 'otplib';

async function loginWithMFA(page: Page, secret: string) {
  await login(page, 'user', 'pass');

  // Generate TOTP code
  const code = authenticator.generate(secret);
  await page.fill('[name="totp"]', code);
  await page.click('button[type="submit"]');
  await page.waitForURL('/dashboard');
}
```

## Tips

- Always use `storageState` to avoid repeated logins — it's the single biggest speedup for E2E suites
- Use environment variables for credentials, never hardcode them
- For CI, consider a dedicated test user with stable credentials
- Use `page.waitForURL()` instead of arbitrary `waitForTimeout()` after login

Copyright (c) 2026 Context Hub Contributors.
Published under the MIT License, which you can read in full there.
Shown as published on GitHub, with credit and a link to the original.
Read it before you use it.

Are you the author?

This skill passed our automated safety check.
Show it in your README with the badge below.
It links readers back to this page. How the badge works

Featured on Scroll AI Now, passed its automated safety check

Markdown
[![Featured on Scroll AI Now, passed its automated safety check](https://scrollainow.com/badge/safety-checked.svg)](https://scrollainow.com/skills/login-flows/)
HTML
<a href="https://scrollainow.com/skills/login-flows/"><img src="https://scrollainow.com/badge/safety-checked.svg" alt="Featured on Scroll AI Now, passed its automated safety check" height="28"></a>

More skills

All agent skills

Try it in your browser

Today's AI news, one card per swipe.
Free to start.

Open the web app