MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / handler

Function handler

pages/api/v1/confirm.ts:99–397  ·  view source on GitHub ↗
(req: NextRequest)

Source from the content-addressed store, hash-verified

97const headers = { "Content-Type": "application/json" };
98
99export default async function handler(req: NextRequest) {
100 try {
101 console.log("/api/v1/confirm called!");
102 // Handle CORS preflight request
103 if (req.method === "OPTIONS") {
104 return new Response(undefined, { status: 200 });
105 }
106 // Handle non-POST requests
107 if (req.method !== "POST") {
108 return new Response(
109 JSON.stringify({
110 error: "Only POST requests allowed",
111 }),
112 {
113 status: 405,
114 headers,
115 },
116 );
117 }
118
119 // Authenticate that the user is allowed to use this API
120 let token = req.headers
121 .get("Authorization")
122 ?.replace("Bearer ", "")
123 .replace("bearer ", "");
124
125 if (!token) {
126 return new Response(JSON.stringify({ error: "Authentication failed" }), {
127 status: 401,
128 headers,
129 });
130 }
131
132 // Check that the user hasn't surpassed the rate limit
133 if (ratelimitProduction) {
134 const { success } = await ratelimitProduction.limit(token);
135 if (!success) {
136 return new Response(
137 JSON.stringify({ error: "Rate limit hit (30 requests/10s)" }),
138 {
139 status: 429,
140 headers,
141 },
142 );
143 }
144 }
145
146 let org: OrgJoinIsPaid | null = null;
147 if (token) {
148 const authRes = await supabase
149 .from("organizations")
150 .select("*, is_paid(*)")
151 .eq("api_key", token)
152 .single();
153 if (authRes.error) throw new Error(authRes.error.message);
154 org = authRes.data;
155 }
156 if (!org) {

Callers

nothing calls this directly

Calls 6

getHostFunction · 0.90
constructHttpRequestFunction · 0.90
makeHttpRequestFunction · 0.90
processAPIoutputFunction · 0.90
replaceVariablesFunction · 0.90
reformatActionDataFunction · 0.85

Tested by

no test coverage detected