create-api-route
Skill1 starsChanged 4 months agoMITView on GitHub
Generate a server-side Next.js API route for Supabase auth (login, logout, callback, session). These routes manage Supabase SSR cookies and run server-side. Do NOT use this skill to create proxy routes for DaaS data — the UI calls DaaS directly using Authorization Bearer tokens instead. Use when the user needs a new auth endpoint or server-side Supabase route.
In this repository59 other files it gives its agents.
- add-buildpadSkill
- add-external-oauthSkill
- add-filesSkill
- add-i18nSkill
- add-microappSkill
- add-microfrontendSkill
- add-microfrontend-zonesSkill
- add-multitenancySkill
- add-usersSkill
- amplify-env-varsSkill
- authentication-proxySkill
- buildpad-debugSkill
- buildpad-discoverySkill
- buildpad-implSkill
- buildpad-referenceSkill
- buildpad-reviewSkill
- buildpad-spec-batchSkill
- buildpad-spec-designSkill
- buildpad-spec-initSkill
- buildpad-spec-quickSkill
- buildpad-spec-requirementsSkill
- buildpad-spec-statusSkill
- buildpad-spec-tasksSkill
- buildpad-steering-customSkill
- buildpad-steeringSkill
- buildpad-validate-designSkill
- buildpad-validate-gapSkill
- buildpad-validate-implSkill
- buildpad-verify-completionSkill
- code-simplificationSkill
- context-engineeringSkill
- create-collectionSkill
- create-componentSkill
- create-cronSkill
- create-featureSkill
- create-form-builderSkill
- create-migrationSkill
- create-projectSkill
- create-rbacSkill
- create-serviceSkill
- create-testsSkill
- create-workflowSkill
- daas-platformSkill
- debugging-and-error-recoverySkill
- generate-docsSkill
- git-workflow-and-versioningSkill
- grant-module-accessSkill
- hooks-extensionsSkill
- idea-refineSkill
- incremental-implementationSkill
- manage-scopeSkill
- performance-optimizationSkill
- planning-and-task-breakdownSkill
- relational-permissionsSkill
- review-codeSkill
- security-and-hardeningSkill
- spec-driven-developmentSkill
- subagent-delegationSkill
- worker-messagingSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 71
When an aggregate parameter is present, the GET handler returns computed values instead of individual items.
- Distinctive: line 77
All routes must check auth:
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Create API Route
Generate a server-side Supabase auth route. These routes manage HTTP-only cookies for Supabase SSR sessions.
Important: Only create auth routes here. Data routes (items, fields, files, etc.) are NOT needed — the UI calls DaaS directly using
Authorization: Bearer <supabase-jwt>. CORS is handled by DaaS viaCORS_ORIGINSenv var.
Auth Routes Only
app/api/auth/
├── login/route.ts # POST — Supabase signInWithPassword
├── logout/route.ts # POST — Supabase signOut
├── callback/route.ts # GET — OAuth/magic-link code exchange
└── user/route.ts # GET — Current user from server-side sessionRoute Template
import { NextRequest, NextResponse } from "next/server";
import { createClient } from "@/lib/supabase/server";
type RouteParams = { params: Promise<{ collection: string }> };
export async function GET(request: NextRequest, { params }: RouteParams) {
const { collection } = await params;
const supabase = await createClient();
const { searchParams } = new URL(request.url);
// Parse query parameters
const limit = parseInt(searchParams.get("limit") || "100");
const offset = parseInt(searchParams.get("offset") || "0");
const sort = searchParams.get("sort");
const filter = searchParams.get("filter");
let query = supabase.from(collection).select("*", { count: "exact" });
query = query.range(offset, offset + limit - 1);
if (sort)
query = query.order(sort.replace("-", ""), {
ascending: !sort.startsWith("-"),
});
const { data, error, count } = await query;
if (error)
return NextResponse.json(
{ errors: [{ message: error.message }] },
{ status: 500 },
);
return NextResponse.json({
data,
meta: { total_count: count, filter_count: count },
});
}Query Parameters
fields— Comma-separated field names or*filter— JSON filter object{ "status": { "_eq": "published" } }sort— Sort field(s) with-prefix for descendinglimit,offset— Paginationaggregate— Aggregate functions:aggregate[count]=idoraggregate={"count":["id"]}groupBy— Group aggregate results by field(s)
When an aggregate parameter is present, the GET handler returns computed values instead of individual items. Supported operations: count, countDistinct, countAll, sum, sumDistinct, avg, avgDistinct, min, max. Response format: { data: [{ count: { id: 42 } }] } (no pagination meta).
⚠️ Field Name Verification: Before using any field name in
sort,fields, orfilterparameters, verify it exists in the DaaS schema usingmcp_daas_schemaormcp_daas_fields. Using a non-existent field (e.g.,sort=-date_createdwhen the actual column iscreated_at) causes DaaS to return a 500 error with no helpful message. Never assume field names — always check the schema first.
Authentication
All routes must check auth:
const supabase = await createClient();
const {
data: { user },
} = await supabase.auth.getUser();
if (!user)
return NextResponse.json(
{ errors: [{ message: "Unauthorized" }] },
{ status: 401 },
);Input Validation (Zod)
import { z } from "zod";
const schema = z.object({
name: z.string().min(1).max(255),
status: z.enum(["draft", "published"]),
});
const validated = schema.parse(body);Required Tests
Create tests/api/[collection].spec.ts with:
- GET all items (200) + query parameters
- POST create with valid data (201) + invalid data (400)
- GET single item (200) + non-existent (404)
- PATCH update (200) + non-existent (404)
- DELETE item (200/204) + non-existent (404)
References
- API route patterns
- API authorization
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

