Auth flow

From rnavarych/alpha-engineer · View interactive version

Auth flow is an AI agent skill from the GitHub repository rnavarych/alpha-engineer. Implement complete authentication flows: login, signup, forgot-password pages, JWT + refresh tokens, session-based auth, social login (Google, GitHub, Apple), MFA/2FA, protected routes via middleware, and role-based UI rendering.

How to use this skill

Skill file

Auth Flow Implementation

When to Use

Activate when adding authentication or authorization to a fullstack application -- login/signup pages, protected routes, social login, token management, or role-based access control.

Auth Library Selection

| Library | Framework | Session Store | OAuth Built-in | MFA Support |

|-------------|---------------|-----------------|----------------|-------------|

| NextAuth.js / Auth.js | Next.js, SvelteKit | DB / JWT | Yes | Via adapter |

| Lucia | Any | DB | Manual | Manual |

| Clerk | Any | Managed | Yes | Yes |

| Supabase Auth| Any | Managed | Yes | Yes |

Login / Signup Flow

  1. Form UI -- use react-hook-form + zod for validation. Fields: email, password, confirm password (signup).
  2. API endpoint -- validate input with Zod, hash password with bcrypt (cost 12+) or argon2, store user in DB.
  3. Session creation -- issue a session token (stored in httpOnly, secure, sameSite=lax cookie) or JWT pair.
  4. Redirect -- on success redirect to the dashboard or the originally requested page (store callbackUrl).

JWT + Refresh Token Strategy

Social Login (OAuth 2.0)

  1. Configure OAuth apps in Google Cloud Console, GitHub Settings, Apple Developer.
  2. Set redirect URIs to {APP_URL}/api/auth/callback/{provider}.
  3. Use NextAuth.js providers or implement the OAuth flow manually (authorization code + PKCE).
  4. On first social login, create a local user record. On subsequent logins, link to the existing account by email.
  5. Handle edge case: user signs up with email/password, then tries social login with the same email -- prompt to link accounts.

MFA / 2FA Implementation

Protected Routes (Middleware)

// Next.js middleware.ts
export function middleware(request: NextRequest) {
  const token = request.cookies.get('session-token');
  if (!token && request.nextUrl.pathname.startsWith('/dashboard')) {
    return NextResponse.redirect(new URL('/login', request.url));
  }
}
export const config = { matcher: ['/dashboard/:path*', '/api/protected/:path*'] };

Role-Based UI Rendering

Common Pitfalls

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.