javascript - JS: How to prevent losing session per refresh after logging in in SoundCloud API -
i'm making dashboard , pulling info soundcloud api. i'm relatively new api , got far being able pull soundcloud widget per track listed. problem everytime refresh, signed out (i think). there way session remain if user example refreshes page? have right now:
function connecttosoundcloud(){ //intialize auth sc sc.initialize({ client_id: sc_client_id, redirect_uri: sc_redirect_uri }); //initiate auth popup sc.connect(function() { sc.get('/me', function(me) { if (me.username) { document.getelementbyid('btn-disconnectfromsoundcloud').style.display=""; document.getelementbyid('btn-connecttosoundcloud').style.display="none"; } $.ajax({ type: "get", url: "http://api.soundcloud.com/tracks.json?client_id="+sc_client_id+"", error: function(result, status){ }, success: function(result, status){ //code display tracks here } }); }); }); }
any appreciated. cheers.
have concidered jstorage
? download here. import jstorage.js file code , go. <script src="your_folder/jstorage.js"></script>
can store logged in user this:
sc.connect(function() { sc.get('/me', function(me) { $.jstorage.set('userinfo',me); // store user storage console.log("logged in userid: "+ me.id); console.log('logged in username: '+me.username); location.reload(); // reloads page }); });
then whenever want info logged in user, use:
var loggedinuser = $.jstorage.get('userinfo');
to sign out, use
$.jstorage.deletekey('userinfo'); // delete logged in user location.reload(); // reloads page
Comments
Post a Comment