MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / handler

Function handler

apps/web/pages/api/invites/join-button.ts:13–51  ·  view source on GitHub ↗
(
  request: NextApiRequest,
  response: NextApiResponse
)

Source from the content-addressed store, hash-verified

11type PostProps = Props & {};
12
13export default async function handler(
14 request: NextApiRequest,
15 response: NextApiResponse
16) {
17 if (request.method === 'OPTIONS') {
18 return preflight(request, response, ['POST']);
19 }
20 cors(request, response);
21
22 const { communityId }: PostProps = request.body;
23
24 const permissions = await PermissionsService.get({
25 request,
26 response,
27 params: { communityId },
28 });
29
30 if (!permissions.access) {
31 return response.status(401).json({});
32 }
33
34 if (request.method === 'POST') {
35 const invites = await findInvitesByEmail(permissions.auth?.email!, {
36 accountsId: communityId,
37 });
38 if (invites.length) {
39 await acceptInvite(invites[0].id, permissions.auth?.email!);
40 } else {
41 await joinCommunity(
42 permissions.auth?.email!,
43 communityId,
44 permissions.auth?.id!
45 );
46 }
47 return response.status(200).json({});
48 }
49
50 return response.status(405).json({});
51}

Callers

nothing calls this directly

Calls 6

preflightFunction · 0.90
corsFunction · 0.90
findInvitesByEmailFunction · 0.90
acceptInviteFunction · 0.90
joinCommunityFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected