Add auth

From schuettc/claude-code-plugins · View interactive version

Add auth is an AI agent skill from the GitHub repository schuettc/claude-code-plugins. Adds Cognito authentication and route protection. Use when adding login, signup, authentication, or user management.

How to use this skill

Skill file

Add Auth — Cognito Authentication

You are adding Cognito authentication to protect API routes and manage user accounts.

Prerequisites

What To Do

Phase 1: Plan

Based on the migration plan, show the user:

Explain the auth flow before asking questions:

"Here's how authentication will work in your app:

  1. New users sign up with their email and a password
  2. They receive a verification code by email (this confirms they own the email)
  3. After verifying, they can sign in
  4. When signed in, the browser stores a token that gets sent with every API request
  5. Your API checks the token and rejects requests without one"

Ask the user:

  1. "Here are the routes I'll protect — does this look right?" — Explain: "Protected routes require the user to be signed in. Public routes work for everyone."
  2. "Do you want email verification for new users?" — Explain: "Recommended — it prevents fake accounts. Users get a 6-digit code by email after signing up. Without it, anyone can sign up with any email address."
  3. "Password requirements — min 8 characters, uppercase, lowercase, number, symbol. Sound good?" — Explain: "These are standard security defaults. You can relax them but it's not recommended."
  4. "Do you want social login (Sign in with Google)?" — Explain: "This adds complexity. I'd recommend starting without it — you can always add it later."
  5. "Should users be able to reset their password via email?" — Explain: "Users who forget their password get a reset code by email. Almost always yes."

Phase 2: Execute

  1. Create infrastructure/lib/auth-stack.ts
  1. Add Cognito Authorizer to API Gateway
  1. Create React auth integration (if frontend exists)
  1. Update API client to include auth token:

Update frontend/src/lib/api.ts:

```typescript

import { getIdToken } from './auth';

export async function apiFetch(path: string, options?: RequestInit) {

const token = await getIdToken();

const headers: Record<string, string> = {

'Content-Type': 'application/json',

...options?.headers as Record<string, string>,

};

if (token) {

headers['Authorization'] = Bearer ${token};

}

const response = await fetch(${API_BASE}${path}, { ...options, headers });

if (!response.ok) throw new Error(API error: ${response.status});

return response.json();

}

```

  1. Update React Router to protect routes:

```tsx

<Route path="/dashboard" element={

<ProtectedRoute>

<DashboardPage />

</ProtectedRoute>

} />

```

Phase 3: Verify

  1. Run cd infrastructure && npx cdk synth to verify compilation
  2. Show the user: Cognito config, protected vs public routes, frontend auth integration
  3. Update .migration/plan.md to mark add-auth as complete

Important Notes

Security

Best Practices

Testing Auth

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.