我一直在到处寻找这个问题的可能解决方案,但似乎无法提出任何特别的建议。从修改我的回调到 Hapi 中的各种其他修补,我无法得到在 Angular 端解决的 promise 。奇怪的是,Twitter 弹出窗口不会关闭。如果我手动关闭它,那么 promise 就会被拒绝。
所以,我不得不配置它来解决被拒绝的 promise ,这真是令人讨厌......
//Angular Method
$scope.addTwitter = function(){
$auth.authenticate('twitter').then(function(res){
// success
}, function(res){
// failure
});
};
//Hapi Route
//Handles both POST and GET and will successfully authenticate for Twitter on /auth/twitter
var User = require('../../models/user');
module.exports = {
description: 'Twitter oAuth for the front-end.',
tags:['twitter'],
auth: {
strategies: ['twitter'],
mode: 'try'
},
handler: function(request, reply){
if (!request.auth.isAuthenticated){
return reply('Authentication failed due to: ' + request.auth.error.message).code(400);
}
if(request.auth.isAuthenticated){
User.addTwitter(request.state['hapi-cookie'].id, request.auth.credentials, function(err, results){
//Twitter Object
//console.log(request.auth.credentials)
reply().code(200);
//return reply.redirect('/#/thanks');
});
}
}
};
在过去的几天里,我尝试了很多不同的方法来让它正常工作。唉,我在这里。感谢您的帮助!
最佳答案
对于 future 的任何人......
我最终创建了带有窗口对象的弹出窗口,并长时间轮询 session 中的更改以通知成功/失败的尝试。如果您将 Angular 与 Hapi 结合使用,这是最容易做到的。
关于javascript - ngSatellizer 和 Hapi/Bell 不能很好地协同工作。 Promise 不会解决 Twitter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27977240/