authentication
Use when adding sign-in/sign-up or session handling to a SaaS app — set up Auth.js (NextAuth) or a hosted provider with secure sessions, OAuth + email, and server-side session checks that protect routes and actions.
Works with
---
name: authentication
description: Use when adding sign-in/sign-up or session handling to a SaaS app — set up Auth.js (NextAuth) or a hosted provider with secure sessions, OAuth + email, and server-side session checks that protect routes and actions.
license: MIT
---
# Authentication
## Overview
Authentication is the gate to everything else, so don't hand-roll it. Use **Auth.js (NextAuth)** with the Drizzle adapter, or a hosted provider (Clerk/Supabase/WorkOS) if you want MFA and user management out of the box. The non-negotiables: httpOnly session cookies, server-side session resolution, and a single `requireSession()` helper used by every protected route and action.
## When to use
- Adding login, signup, OAuth, or magic-link auth.
- Protecting routes, server actions, or route handlers.
- Resolving "who is the current user/org" on the server.
## The pattern (Auth.js)
```ts
// src/server/auth/index.ts
import "server-only";
import NextAuth from "next-auth";
import { DrizzleAdapter } from "@auth/drizzle-adapter";
import Google from "next-auth/providers/google";
import { db } from "@/server/db/client";
import { env } from "@/env";
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: DrizzleAdapter(db),
session: { strategy: "database" },
secret: env.AUTH_SECRET,
providers: [Google],
});
```
```ts
// src/server/auth/require.ts
import "server-only";
import { redirect } from "next/navigation";
import { auth } from "@/server/auth";
export async function requireSession() {
const session = await auth();
if (!session?.user) redirect("/sign-in");
return session;
}
```
Use it in a layout to protect a whole route group:
```ts
// src/app/(app)/layout.tsx
export default async function AppLayout({ children }) {
await requireSession(); // server-side, runs before render
return <>{children}</>;
}
```
## Security essentials
- **Sessions in httpOnly, Secure, SameSite=Lax cookies.** Never store tokens in `localStorage`.
- **Resolve sessions on the server** (`auth()` in components/actions), not from a client fetch you trust.
- **Rotate + expire.** Set sensible session max-age; support sign-out everywhere.
- **Hash passwords with argon2/bcrypt** only if you truly own credentials — prefer OAuth/magic-link.
## Pitfalls
- **Trusting client-side auth state for authorization** — it's a UX hint only; always re-check on the server.
- **JWT sessions when you need instant revocation** — use the database strategy if "log out all devices" matters.
- **Leaking whether an email exists** — keep sign-in errors generic (pair with `auth-screens` UX).
- **No CSRF protection on credential posts** — Auth.js handles this; don't bypass it with custom forms.
- **Protecting only the UI** — a route handler without a session check is wide open.
## Hand-off
A trustworthy `requireSession()`. `multi-tenancy` turns the user into an active org; `authorization-rbac` checks what that user may do.More Security skills
azure-cost
microsoft/azure-skills
Azure cost management: query costs, forecast spending, optimize to reduce waste. WHEN: \"Azure costs\", \"Azure bill\", \"cost breakdown\", \"how much am I spending\", \"forecast spending\", \"optimize costs\", \"reduce spending\", \"orphaned resources\", \"rightsize VMs\", \"cost spike\", \"reduce storage costs\", \"AKS cost\". DO NOT USE FOR: deploying resources, provisioning, diagnostics, or security audits.
entra-app-registration
microsoft/azure-skills
Guides Microsoft Entra ID app registration, OAuth 2.0 authentication, and MSAL integration. USE FOR: create app registration, register Azure AD app, configure OAuth, set up authentication, add API permissions, generate service principal, MSAL example, console app auth, Entra ID setup, Azure AD authentication. DO NOT USE FOR: Key Vault secrets (use azure-keyvault-expiration-audit), general Azure resource security guidance.
azure-messaging
microsoft/azure-skills
Troubleshoot and resolve issues with Azure Messaging SDKs for Event Hubs and Service Bus. Covers connection failures, authentication errors, message processing issues, and SDK configuration problems. WHEN: event hub SDK error, service bus SDK issue, messaging connection failure, AMQP error, event processor host issue, message lock lost, message lock expired, lock renewal, lock renewal batch, send timeout, receiver disconnected, SDK troubleshooting, azure messaging SDK, event hub consumer, service bus queue issue, topic subscription error, enable logging event hub, service bus logging, eventhub python, servicebus java, eventhub javascript, servicebus dotnet, event hub checkpoint, event hub not receiving messages, service bus dead letter, batch processing lock, session lock expired, idle timeout, connection inactive, link detach, slow reconnect, session error, duplicate events, offset reset, receive batch.

