This commit is contained in:
Steve Ruiz 2021-06-28 23:22:23 +01:00
parent 36fc386269
commit 80d2ba5f00
9 changed files with 179 additions and 50 deletions

33
pages/api/pusher-auth.ts Normal file
View file

@ -0,0 +1,33 @@
import { NextApiHandler } from 'next'
import Pusher from 'pusher'
import { v4 as uuid } from 'uuid'
const pusher = new Pusher({
key: '5dc87c88b8684bda655a',
appId: '1226484',
secret: process.env.PUSHER_SECRET,
cluster: 'eu',
})
const PusherAuth: NextApiHandler = (req, res) => {
try {
const { socket_id, channel_name } = req.body
const presenceData = {
user_id: uuid(),
user_info: { name: 'Anonymous' },
}
const auth = pusher.authenticate(
socket_id.toString(),
channel_name.toString(),
presenceData
)
return res.send(auth)
} catch (err) {
res.status(403).end()
}
}
export default PusherAuth