-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth.js
32 lines (27 loc) · 784 Bytes
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require('dotenv').config()
exports.handler = function(event, context, callback) {
let query = event.queryStringParameters
let Pusher = require('pusher')
let pusher = new Pusher({
appId: process.env.PUSHER_APP_ID,
key: process.env.PUSHER_KEY,
secret: process.env.PUSHER_SECRET,
cluster: process.env.PUSHER_CLUSTER,
useTLS: true
})
let presenceData = {
user_id: query.socket_id,
user_info: {
name: query.username
}
}
let auth = JSON.stringify(pusher.authenticate(query.socket_id, query.channel_name, presenceData))
let authCallback = query.callback.replace(/\"/g,"") + "(" + auth + ");"
callback(null, {
statusCode: 200,
headers: {
'Content-Type': 'application/javascript',
},
body: authCallback,
})
}