Last active
March 12, 2021 01:55
-
-
Save onedebos/a4fd8761d2ae391c7867a407153fb773 to your computer and use it in GitHub Desktop.
pages/api/pusher/auth.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {pusher} from '../../../../lib/pusher' | |
export default async function handler( req, res ) { | |
// see https://pusher.com/docs/channels/server_api/authenticating-users | |
const { socket_id, channel_name, username, userLocation } = req.body; | |
// use JWTs here to authenticate users before continuing | |
const randomString = Math.random().toString(36).slice(2); | |
const presenceData = { | |
user_id: randomString, | |
user_info: { | |
username: "@" + username, | |
userLocation | |
}, | |
}; | |
try { | |
const auth = pusher.authenticate(socket_id, channel_name, presenceData); | |
res.send(auth); | |
} catch (error) { | |
console.error(error) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment