pn-auth-patterns

pn-auth-patterns is a skill for Claude Code, Codex from perniemann/pnCore. It costs 44 tokens per session (1,767 once invoked), scanned B, original, MIT.

A collection of patterns for adding user sign-in, social login, sessions, access rules, and token-based authentication to applications. OAuth2 is a standard for delegated login, while JWTs are signed tokens used to carry login information.

In plain words
What is it for?
Use it when implementing or reviewing authentication, OAuth2 login flows, JWT rotation, session invalidation, role-based access, or provider choices for React, Next.js, Supabase, and enterprise applications.
Why use it?
It helps choose between session-based login, JWTs, and hosted authentication services while handling token expiry, refresh, and access control consistently.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/perniemann/pncore/pn-auth-patterns
Any agent
npx skills add perniemann/pnCore --skill pn-auth-patterns
Clone the repo
git clone --depth 1 https://github.com/perniemann/pnCore

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for pn-auth-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/perniemann/pncore/pn-auth-patterns.svg)](https://agentmods.dev/skills/perniemann/pncore/pn-auth-patterns)
Your own site
<a href="https://agentmods.dev/skills/perniemann/pncore/pn-auth-patterns"><img src="https://agentmods.dev/badge/skills/perniemann/pncore/pn-auth-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 44 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,767 The whole file, excluding the scripts and references it only reads on demand.
Security scan B 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00044 $0.01767
Opus 5 $0.00022 $0.00883
Sonnet 5 $0.00009 $0.00353
Haiku 4.5 $0.00004 $0.00177

Measured 2d ago against content hash 967fa081c6f5, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade B, and why

pn-auth-patterns scanned grade B with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Sends data to an external URLmediumData exfiltration

A POST to an outside endpoint may be telemetry or may be exfiltration; either way the mod talks to somewhere, and you should know where.

const tokenRes = await fetch("https://example.invalid/oauth2/token", { method: "POST",
packages/pn-core-mcp/content/skills/backend/pn-auth-patterns/SKILL.md · 200 lines

How it starts

The opening of the file, as written. The whole thing — 200 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Auth patterns

When to use

  • Implementing authentication or authorisation for the first time in a project
  • Choosing between session-based, JWT, or third-party auth (Clerk, Supabase Auth, Auth0)
  • Adding OAuth2 / social login flows
  • Reviewing JWT expiry, refresh token rotation, or session invalidation
  • Adding role-based or attribute-based access control (RBAC/ABAC)

Library decision matrix

Project Recommended When to use
Next.js (full-stack) NextAuth.js v5 (Auth.js) Open-source, multi-provider, sessions or JWT, edge-ready
Next.js with managed UX Clerk Drop-in UI components, org/team support, minimal setup
Supabase project Supabase Auth Already on Supabase; use built-in auth helpers
Any React SPA (separate API) Auth.js or custom JWT When backend is separate
Enterprise / B2B Auth0 or WorkOS SSO, SAML, SCIM provisioning

NextAuth.js v5 (Auth.js)

// auth.ts
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";
import Credentials from "next-auth/providers/credentials";

export const { handlers, signIn, signOut, auth } = NextAuth({
  providers: [
    GitHub({ clientId: process.env.AUTH_GITHUB_ID!, clientSecret: process.env.AUTH_GITHUB_SECRET! }),
    Credentials({
      credentials: { email: {}, password: {} },
      async authorize({ email, password }) {
        const user = await verifyCredentials(email as string, password as string);
        return user ?? null; // null triggers "Invalid credentials" error
      },
    }),
  ],
  session: { strategy: "jwt" },
  callbacks: {
    async jwt({ token, user }) {
      if (user) token.role = user.role; // attach custom claims
      return token;
    },
    async session({ session, token }) {
      session.user.role = token.role as string;
      return session;
    },
  },
});

// Route handler: app/api/auth/[...nextauth]/route.ts
export { handlers as GET, handlers as POST } from "@/auth";

// Protect a server component
import { auth } from "@/auth";
import { redirect } from "next/navigation";

export default async function ProtectedPage() {
  const session = await auth();
  if (!session) redirect("/login");
  return <div>Welcome, {session.user?.name}</div>;
}

Read the full file on GitHub · 200 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 200 lines · 44 tokens per session scan B 967fa081c6f5

Subscribe to this mod's changes

pn-auth-patterns is a skill published in the GitHub repository perniemann/pnCore (0 stars, last pushed 2d ago), licensed MIT. It adds 44 tokens to every session and 1,767 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it B with 1 finding (sends data to an external url). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories

t-800-factory-scaffold

Procedural checklist CREATE артефактов T-800 через factory (не ad-hoc Write в agents/skills/commands/rules/hooks). Use when /t800-start, factory CREATE, factory-brief, или «собери агента/skill/command». Do NOT use when /t800-fix PATCH, обычный код без Cursor-артефактов, или обучение новичка (→ Task t-800-operator).

Khar-AG/t-800-agent · 100 tokens

t-800-command-chains

Как читать и обновлять machine-readable commandchains T-800 и не плодить orphan commands/agents. Use when правка commands/, registry, graph команд↔агенты, или после добавления /t800- команды. Do NOT use when soft prose orchestration в agent body без JSON, plugin-audit полный отчёт (→ t-800-plugin-auditor), или product…

Khar-AG/t-800-agent · 91 tokens

t-800-fix-pack

Структура fix-pack и constraints factory PATCH для /t800-fix. Use when правка существующего артефакта, fix-packs/ .md, audit→fixpack, или mode PATCH. Do NOT use when полный CREATE /t800-start, Loop report-only (/t800-loop), или doctor/plugin-audit без PATCH.

Khar-AG/t-800-agent · 79 tokens

t-800-plugin-sync

Procedural install/sync T-800 в /.cursor/plugins/local с CONTENTDRIFT --check и обязательным Reload Window. Use when install-plugin, sync --check, CONTENTDRIFT, stale marketplace pin, или «плагин не обновился». Do NOT use when KB sync-docs (/t-800-sync → t-800-knowledge-base), factory CREATE артефактов, или MIR в…

Khar-AG/t-800-agent · 98 tokens

t-800-run-gates

Какие machine gates гонять перед «готово» в прогоне T-800 (rungate, frontmatter, doctor/audit по режиму). Use when перед сдачей CREATE/PATCH, STATE Gates, strict-create, или exit code gates. Do NOT use when проектирование промпта (prompt-craft), обучение новичка, или cloud conversation hooks как sole-gate (P1).

Khar-AG/t-800-agent · 89 tokens

t-800-knowledge-base

Карта KB плагина T-800 Agent для ОБНОВЛЕНИЯ базы знаний (sync, CHANGELOG). НЕ вызывать для ответов пользователю — для этого Task(t-800-operator).

Khar-AG/t-800-agent · 50 tokens