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

Function handler

pages/api/team.ts:36–93  ·  view source on GitHub ↗
(req: NextRequest)

Source from the content-addressed store, hash-verified

34};
35
36export default async function handler(req: NextRequest): Promise<Response> {
37 if (req.method !== "GET") {
38 return new Response(
39 JSON.stringify({
40 error: "Only GET requests allowed",
41 }),
42 { status: 405, headers },
43 );
44 }
45 const { session } = await getSessionFromCookie(req);
46 if (!session) {
47 return new Response(JSON.stringify({ error: "Unauthorized" }), {
48 status: 401,
49 headers,
50 });
51 }
52 const usersProfileRes = await supabase
53 .from("profiles")
54 .select("org_id")
55 .eq("id", session.user.id)
56 .single();
57 if (usersProfileRes.error) {
58 return new Response(JSON.stringify({ error: "Error fetching data" }), {
59 status: 500,
60 headers,
61 });
62 }
63 if (usersProfileRes.data === null || usersProfileRes.data.org_id === null) {
64 return new Response(JSON.stringify({ error: "User doesn't have an org" }), {
65 status: 400,
66 headers,
67 });
68 }
69
70 const { data, error } = await supabase
71 .from("profiles")
72 .select("full_name, email_address, avatar_url")
73 .eq("org_id", usersProfileRes.data!.org_id);
74
75 if (error) {
76 console.error(error.message);
77 return new Response(
78 JSON.stringify({ message: "Error fetching data: " + error.message }),
79 {
80 status: 500,
81 headers,
82 },
83 );
84 }
85 if (data === null) {
86 console.error("No data returned from organizations select");
87 return new Response(JSON.stringify({ message: "Error fetching data" }), {
88 status: 500,
89 headers,
90 });
91 }
92 return new Response(JSON.stringify(data), { status: 200, headers });
93}

Callers

nothing calls this directly

Calls 1

getSessionFromCookieFunction · 0.90

Tested by

no test coverage detected