( request: NextApiRequest, response: NextApiResponse )
| 4 | const PUSH_SERVICE_KEY = process.env.PUSH_SERVICE_KEY; |
| 5 | |
| 6 | export default async function handler( |
| 7 | request: NextApiRequest, |
| 8 | response: NextApiResponse |
| 9 | ) { |
| 10 | try { |
| 11 | const { push_token, current_user, channel_id, thread_id, community_id } = |
| 12 | JSON.parse(request.body); |
| 13 | if (!current_user) { |
| 14 | return response.status(500).json({ error: 'missing current user' }); |
| 15 | } |
| 16 | if (!push_token) { |
| 17 | return response.status(500).json({ error: 'missing push token' }); |
| 18 | } |
| 19 | if (!PUSH_SERVICE_KEY) { |
| 20 | return response.status(500).json({ error: 'missing push service key' }); |
| 21 | } |
| 22 | if (push_token !== PUSH_SERVICE_KEY) { |
| 23 | return response.status(500).json({ error: 'invalid push token' }); |
| 24 | } |
| 25 | |
| 26 | if (channel_id) { |
| 27 | const result = await Session.canAuthAccessChannel( |
| 28 | current_user, |
| 29 | channel_id |
| 30 | ); |
| 31 | return response.status(result ? 200 : 403).json({}); |
| 32 | } else if (thread_id) { |
| 33 | const result = await Session.canAuthAccessThread(current_user, thread_id); |
| 34 | return response.status(result ? 200 : 403).json({}); |
| 35 | } else if (community_id) { |
| 36 | const result = await Session.canAuthAccessCommunity( |
| 37 | current_user, |
| 38 | community_id |
| 39 | ); |
| 40 | return response.status(result ? 200 : 403).json({}); |
| 41 | } |
| 42 | return response.status(500).json({ error: 'missing parameters' }); |
| 43 | } catch (error: any) { |
| 44 | console.error(error); |
| 45 | return response.status(error.status || 500).json({}); |
| 46 | } |
| 47 | } |
nothing calls this directly
no test coverage detected