Last active
August 29, 2015 14:24
-
-
Save jessepollak/2b92aff3cc60db392ef8 to your computer and use it in GitHub Desktop.
Automatic logout with Clef with 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
<?php | |
// On the backend we have the Pusher object set up | |
$PUSHER_APP_ID = 'YOUR_APP_ID'; | |
$PUSHER_APP_KEY = 'YOUR_APP_KEY'; | |
$PUSHER_APP_SECRET = 'YOUR_APP_SECRET'; | |
$pusher = new Pusher( $PUSHER_APP_KEY, $PUSHER_APP_SECRET, $PUSHER_APP_ID ); | |
// then, when a user logs out via Clef, we trigger a logout message | |
// on their user ID push channel | |
$pusher->trigger($user->ID, 'logout', array(success => true)); | |
<?php | |
// then, in the frontend, we set up Pusher to listen for that message | |
// and redirect the user when it's heard | |
if (isset($user->clef_id)) { ?> | |
<script src="//js.pusher.com/2.2/pusher.min.js"></script> | |
<script> | |
var pusher = new Pusher("<?php echo $PUSHER_APP_ID ?>"); | |
var channel = pusher.subscribe("<?php echo $user->ID ?>"); | |
channel.bind('logout', function(data) { window.location.reload() }); | |
</script> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment