Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Auth0 rule to publish a signup/login event to Pusher
function (user, context, callback) {
var Pusher = require('pusher@1.2.1');
var pusher = new Pusher({
appId: '<INSERT_YOUR_PUSHER_APP_ID>',
key: '<INSERT_YOUR_PUSHER_APP_KEY>',
secret: '<INSERT_YOUR_PUSHER_APP_SECRET>',
cluster: '<INSERT_YOUR_PUSHER_APP_CLUSTER>',
encrypted: true
});
user.app_metadata = user.app_metadata || {};
var channel = 'auth0';
var event = 'user-signedUp';
var userClonedObj = JSON.parse(JSON.stringify(user));
userClonedObj.country = context.request.geoip.country_name;
if (user.app_metadata.signedUp) {
event = 'user-loggedIn';
} else {
user.app_metadata.signedUp = true;
auth0.users.updateAppMetadata(user.user_id, user.app_metadata);
}
console.log(userClonedObj);
pusher.trigger(channel, event, userClonedObj);
callback(null, user, context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment