MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / handler

Function handler

apps/web/pages/api/jwt/who.ts:6–36  ·  view source on GitHub ↗
(
  request: NextApiRequest,
  response: NextApiResponse
)

Source from the content-addressed store, hash-verified

4const PUSH_SERVICE_KEY = process.env.PUSH_SERVICE_KEY;
5
6export default async function handler(
7 request: NextApiRequest,
8 response: NextApiResponse
9) {
10 try {
11 const { push_token } = JSON.parse(request.body);
12 if (!push_token) {
13 throw 'missing push token';
14 }
15 if (!PUSH_SERVICE_KEY) {
16 throw 'missing push service key';
17 }
18 if (push_token !== PUSH_SERVICE_KEY) {
19 throw 'invalid push token';
20 }
21
22 const token = await Session.token(request);
23 if (!token) {
24 throw 'invalid authorization token';
25 }
26
27 if (!token.id) {
28 throw 'missing user id on authorization token';
29 }
30
31 return response.send(token.id);
32 } catch (error: any) {
33 console.error({ error });
34 return response.status(error.status || 500).json({});
35 }
36}

Callers

nothing calls this directly

Calls 3

tokenMethod · 0.80
errorMethod · 0.65
sendMethod · 0.45

Tested by

no test coverage detected