Not loaded · from tec-knowledge-base
When writing or modifying any BFF route (/api/bff/*) in any TEC app — enforce BFF-first rule, createHandler pattern, auth cookie reading, CSRF protection, and proper gateway proxying.
Claude Code won't load this skill
It ships in tec-knowledge-base at skills/, but Claude Code only loads skills/<name>/SKILL.md and folders listed under skills in plugin.json. Installing the plugin doesn't add it.
All client data fetching goes through /api/bff/* — no exceptions (BFF-first rule, learned from NEW-L production bug).
import { NextRequest, NextResponse } from 'next/server';
import { z } from 'zod';
// Gateway URL — always include NEXT_PUBLIC fallback
const GW = process.env.API_GATEWAY_URL
?? process.env.NEXT_PUBLIC_API_GATEWAY_URL ?? '';
// Input validation schema
const RequestSchema = z.object({
// ... define fields
});
export async function POST(req: NextRequest) {
if (!GW) return NextResponse.json({ error: 'Service unavailable' }, { status: 503 });
// CSRF — only reject when cookie present but mismatched
const csrfCookie = req.cookies.get('tec_csrf')?.value ?? '';
const csrfHeader = req.headers.get('x-csrf-token') ?? '';
if (csrfCookie && csrfCookie !== csrfHeader) {
return NextResponse.json({ error: 'CSRF validation failed' }, { status: 403 });
}
// Auth — read from cookie (NEVER Authorization header only)
const token = req.cookies.get('tec_access_token')?.value;
if (!token) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
// Validate input
const raw = await req.json().catch(() => ({}));
const parsed = RequestSchema.safeParse(raw);
if (!parsed.success) {
return NextResponse.json(
{ error: 'VALIDATION_ERROR', details: parsed.error.flatten() },
{ status: 400 }
);
}
// Build gateway headers
const gwHeaders: Record<string, string> = {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
'Idempotency-Key': crypto.randomUUID(),
};
// Only send x-internal-key if SET — empty string causes gateway 401
if (process.env.INTERNAL_SECRET) {
gwHeaders['x-internal-key'] = process.env.INTERNAL_SECRET;
}
try {
const res = await fetch(`${GW}/api/YOUR_ENDPOINT`, {
method: 'POST',
headers: gwHeaders,
body: JSON.stringify(parsed.data),
});
const data = await res.json().catch(() => ({}));
if (!res.ok) {
console.error('[bff/YOUR_ROUTE] gateway error:', res.status, data);
}
return NextResponse.json(data, { status: res.status });
} catch (err) {
console.error('[bff/YOUR_ROUTE] network error:', (err as Error).message);
return NextResponse.json({ error: 'Service unavailable' }, { status: 503 });
}
}
/api/bff/wallet/balance ← data fetch (cookie auth + token refresh) ✅ USE
/api/bff/payment/approve ← Pi callback handler
/api/bff/payment/complete ← Pi callback handler
/api/bff/payment/create ← Backend-first payment creation (C-76)
/api/bff/payments/history ← payment history list
/api/bff/orders ← order creation
/api/wallet/balance ← ⚠️ LEGACY — Authorization header only, no refresh
SYMPTOM: Page shows 0 balance even though Hub card shows correct balance.
CAUSE: Client hook uses /api/wallet/balance — Authorization header only.
On token expiry → silently returns {balance:0, walletId:null}.
FIX: Switch to /api/bff/wallet/balance (createHandler + auto token refresh).
RULE: ALL client data fetching → /api/bff/* routes ONLY.
NEVER call /api/wallet/*, /api/payments/*, /api/notifications/* from client.
// Hub SSO cookie may use id, sub, or piId — check all
const getUserId = (req: NextRequest): string => {
try {
const raw = req.cookies.get('tec_user')?.value ?? '';
const u = JSON.parse(decodeURIComponent(raw));
return u?.id ?? u?.sub ?? u?.piId ?? '';
} catch { return ''; }
};
Client Components → packages/tec-core-sdk (usePiAuth, useTecWallet)
API Routes (BFF) → @yasser172/tec-sdk (TecSdk.payment.*, TecSdk.auth.*)
FORBIDDEN:
→ tec-sdk npm imported in Client Components
→ window.Pi called directly in API Routes
→ axios / Pi SDK directly in API Routes
What SKILL.md sets; muted values are Claude Code's defaults
Claude Code refuses to install this plugin
.claude-plugin/plugin.json: commands: Invalid input, agents.0: Invalid string: must start with "./", agents.0: Invalid string: must end with ".md", agents.1: Invalid string: must start with "./", agents.1: Invalid string: must end with ".md", agents.2: Invalid string: must start with "./", agents.2: Invalid string: must end with ".md", skills: Invalid input, author: Invalid input: expected object, received string
.claude-plugin/plugin.json: commands: Invalid input, agents.0: Invalid string: must start with "./", agents.0: Invalid string: must end with ".md", agents.1: Invalid string: must start with "./", agents.1: Invalid string: must end with ".md", agents.2: Invalid string: must start with "./", agents.2: Invalid string: must end with ".md", skills: Invalid input, author: Invalid input: expected object, received string
Checked against Claude Code 2.1.332's install rules. The listing below is what the repository ships; Claude Code cannot install it as published.
16 skills in this plugin
/charter-advisorWhen working on any app within the TEC ecosystem — before modifying code, architecture, or CLAUDE.md — load the app's Institutional Charter (C-100→C-115 infra apps + C-124→C-131 user-layer apps) to understand its engineering authority, security model, and P0/P1/P2 gaps./community-marketingWhen building or growing the TEC community on Pi Network channels (Pi Chat, Pi Forum, Telegram, Discord) — apply community-first growth, ambassador programs, and trust-building frameworks./content-strategyWhen creating content for TEC platform — blog posts, social content, Pi community updates, developer docs, or onboarding materials — apply Pi-native content frameworks and audience segmentation.Other plugins' skills for the same job