Last active
May 3, 2017 14:50
-
-
Save eh3rrera/00ee1aeb462777736f4e441694662c5d to your computer and use it in GitHub Desktop.
Auth0 rule to publish a signup/login event to Pusher
This file contains 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
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