ワンクリックで
api-auth-session
Use when changing GitHub OAuth, session cookies, SessionGuard, logout, or authenticated API request identity.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Use when changing GitHub OAuth, session cookies, SessionGuard, logout, or authenticated API request identity.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Use when adding, changing, extracting, or reusing client components, including Storybook stories and controls.
Use when adding or changing forms in apps/client.
Use when adding or changing routes in apps/client.
Use when adding or changing client state, React Query data flow, immutable context values, or Zustand stores.
Use when styling apps/client with Tailwind CSS v4.
Use when adding or changing client API query or mutation hooks.
| name | api-auth-session |
| description | Use when changing GitHub OAuth, session cookies, SessionGuard, logout, or authenticated API request identity. |
Generated from ai/registry.json. Do not edit manually.
Canonical skill: ../../../ai/skills/api-auth-session.md.
Referenced context:
../../../ai/rules/api-auth-session-rules.md../../../ai/architecture/auth-session-flow.md../../../ai/examples/good-auth-session.md../../../ai/architecture/api-app.mdThis file is compiled from canonical AI knowledge files. Edit canonical files under ai, then run npm run ai:sync.
ai/skills/api-auth-session.mdUse this skill when changing GitHub OAuth, session cookies, SessionGuard, logout, or authenticated API request identity.
Preserve the current direct GitHub OAuth flow and HTTP-only hashed session-token model.
ai/rules/api-auth-session-rules.mdai/architecture/auth-session-flow.mdai/examples/good-auth-session.mdai/architecture/api-app.mdSessionGuard and pass request.user.id to services.npm --workspace @capture-flag/api run test for auth/session behavior changes.npm --workspace @capture-flag/api run build after controller, guard, or service changes.ai/rules/api-auth-session-rules.mdRules for GitHub OAuth, session cookies, and authenticated API requests.
code, state, and stored state before authenticating the GitHub user.sess_ and use SessionsService for hashing, lookup, creation, and revocation.SessionGuard and read the authenticated user from AuthenticatedRequest.ai/architecture/auth-session-flow.mdGitHub OAuth creates platform users and HTTP-only sessions for private API access.
AuthController.startGithub asks GithubAuthService to create an OAuth state.cf_oauth_state HTTP-only cookie.read:user user:email scope.AuthController.githubCallback reads code, callback state, and the stored state cookie.UnauthorizedException.GithubAuthService.authenticate exchanges the code, fetches GitHub user data, requires GitHub email permission, resolves a primary verified email with a public email fallback, and upserts the local user/OAuth account.SessionsService.createSession creates a raw sess_ token, stores only its hash, and returns cookie metadata.SessionGuard reads the session cookie, finds a non-revoked unexpired session by token hash, and attaches request.user.request.user.id to services; services own tenant and role checks.Logout revokes the hashed token through SessionsService.revokeToken and clears the session cookie.
ai/examples/good-auth-session.mdSource: apps/api/src/auth/auth.controller.ts (sha256: ea83131ff8f06799060caf72717892ad9d9b3c5c4bc04b4961d3b5aea5ffdb95)
Source: apps/api/src/auth/sessions.service.ts (sha256: 0521de89eada4c22d2fe0ac55cb6a454dae9bde6bf6a751cd7fc1b828c393699)
Source: apps/api/src/auth/session.guard.ts (sha256: 8f1e973b87b842d633d24d4da55b85e4298f7f592dafaa51228b9adf1e131364)
Why this is canonical:
SessionGuard to attach authenticated user data to private requests.const token = `sess_${randomBytes(32).toString("base64url")}`;
const tokenHash = this.hashToken(token);
await this.prisma.session.create({
data: {
userId,
tokenHash,
expiresAt,
},
});
The raw token is returned for the cookie only; the database stores the hash.
const token = request.cookies?.[this.sessions.cookieName];
const session = await this.sessions.findActiveSessionByToken(token);
request.user = {
id: session.user.id,
name: session.user.name,
email: session.user.email,
sessionId: session.id,
};
Private controllers use request.user.id; services then enforce tenant access.
ai/architecture/api-app.mdapps/api is a NestJS API backed by Prisma and PostgreSQL.
request.user.id to services.SessionGuard and AuthenticatedRequest.AuthenticatedApiGuard, then API token tenant/scope guards.ApiTokenGuard directly, followed by tenant/scope guards.UuidParam, the shared wrapper around ParseUUIDPipe, in controllers.support services hold concrete reusable responsibilities such as access, audit, input normalization, read models, credentials, config state, references, validation, writers, or initializers.PrismaService./api/v1./api/v1/docs is filtered to the supported management subset.applyHttpSecurity() before request handling.