operator-app-auth-routing
Use this skill when changing operator app auth routing, Next.js public vs app route groups, `proxy.ts` route protection, auth-aware public chrome, `AccountSlot`, NextAuth session identity, wallet Conn
Files1
View on GitHubSKILL.md.claude/skills/operator-app-auth-routing/SKILL.md
GitHubOperator App Auth Routing
Keep page placement, chrome state, and auth enforcement separate. proxy.ts is the routing contract; route groups and UI chrome should not become alternate auth systems.
Route Groups
- Public pages live under
nodes/operator/app/src/app/(public)/.... - Authenticated app pages live under
nodes/operator/app/src/app/(app)/.... - A public route may still be auth-aware. Example:
/nodescan stay public while showing session-aware account chrome. - Moving a page between route groups is not enough to change auth. Update
proxy.tsand its tests when access changes. - Operator is the node-gallery host. Its own detail page is
/nodes/operator; other nodes are node-at-root apps on their own subdomains unless their local validation guide says otherwise.
Proxy Rules
- Treat
nodes/operator/app/src/proxy.tsas the primary authority for page redirects and/api/v1early rejection. - Keep
APP_ROUTESandconfig.matcherin sync. Matcher drift caused/dashboardand/knowledgeregressions before. - App routes redirect unauthenticated users to
/; authenticated users on/redirect to/chat. - Do not add client-side auth redirects for page protection. Client components can render auth-aware states, but proxy owns access decisions.
Public Chrome
- Use
AccountSlotfor shared identity chrome in public and app headers. AccountSlotusesuseSession()from NextAuth as the identity source. Wallet connection state is only for starting sign-in when no session exists.- Authenticated users should see the user menu and optional app link, never a stale Connect call-to-action just because wallet state lags.
- If public chrome looks wrong after login, fix the session-aware component path before adding wallet-state special cases.
API Rules
/api/v1/public/*is unauthenticated by namespace./api/v1/agent/registeris unauthenticated by explicit exception.- Other
/api/v1/*routes require a NextAuth session unless they carry aBearer cogni_ag_sk_v1_...agent token. - Proxy only provides early rejection. Route handlers must still enforce their own auth and identity rules server-side.
Tests To Update
- Update
nodes/operator/app/tests/unit/auth/proxy-routing.test.tswhenever an app route, public route, API exception, or matcher changes. - Add both unauthenticated and authenticated assertions for new app routes.
- Include nested route examples for path families such as
/knowledge/:id. - Assert public/auth-aware routes pass through without becoming app routes.
- For chrome behavior, add focused component tests around
AccountSlotor the header using mocked NextAuth session state.
Candidate Validation
- Keep
nodes/operator/.cogni/validation.mdin sync with operator public routes, app routes, and auth expectations. /validate-candidatereads node-local validation guides to choose human-axis routes. If this skill changes route policy, update that guide too.- Validate
/nodes/operatoronly for operator gallery/detail changes. For non-operator nodes, validate the node's root/app pages on its own candidate subdomain.
Pitfalls
- Public does not mean session-blind.
/nodescan be public and still render auth-aware account controls. - Route group folders do not enforce auth.
proxy.tsdoes. APP_ROUTESwithout a matchingconfig.matcherentry silently skips proxy execution.config.matcherwithout a matchingAPP_ROUTESentry runs proxy but may pass through unexpectedly.- Wallet
isConnectedis not user identity. NextAuth session is the source of truth for logged-in UI.