所以,我終於得到了我的路線設置和我的SoundCloud認證是偉大的工作。我現在遇到的問題是我無法弄清楚如何在不刷新的情況下將用戶返回到父頁面。到目前爲止,我所做的是創建一個彈出窗口,以便用戶可以進行身份驗證。這將重定向到我指定的Soundcloud回調。然後,我將該回調重定向到我所做的回調,以便關閉彈出窗口。返回用戶對象?
如果我嘗試在認證後對頁面進行任何操作,它會一直啓動Connect with Soundcloud頁面,直到我刷新頁面。刷新頁面後,它會返回用戶和一切正常和花哨。
這裏有前臺功能:
var windowObjectReference;
var strWindowFeatures = "width=420,height=230,resizable,scrollbars=yes,status=1";
function allowLike(){
$('.queueTrack').off('click').on('click', function(){
console.log('clicked like');
thisDiv = $(this);
$.getJSON('/user', function(data){
var token = data.token;
songId = thisDiv.data("songid");
$.ajax({
url: 'https://api.soundcloud.com/me/favorites/' + songId + '?oauth_token=' + token,
type: 'PUT',
success: function(result) {
console.log('u liked' + songId)
},
error: function(){
windowObjectReference = window.open("/auth/soundcloud", "SC_Connect", strWindowFeatures);
}
});
}).error(function(){
console.log('getJSON error');
windowObjectReference = window.open("/auth/soundcloud", "SC_Connect", strWindowFeatures);
});
})
}
和我有以下的後端:
router.get('/auth/soundcloud/callback',
passport.authenticate('soundcloud', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/after-auth.html');
});
的後auth.html關閉彈出很好,但我可以」弄清楚如何在不刷新的情況下將用戶對象返回到父頁面。
我看過一個教程,使用Angular來做到這一點,但它可能沒有使用Angular?
你可以分享你的代碼或創建plunker? –
@BrianBaker添加代碼 –
哎呀我以爲你在使用Angular,我已經準備好了一整本文件:) –