Firebase:在node.js中登录Facebook时出现TRANSPORT_UNAVAILABLE错误

时间:2015-02-10 20:05:43

标签: firebase

我正在尝试在服务器端(node.js)实现社交登录(Facebook和Twitter)。然而,它不断给我一个" TRANSPORT_UNAVAILABLE"错误。有什么想法吗?

代码:

function authHandler(error, authData) {
    if (error) {
        res.send(error);
    }
    else {
        res.send("Authenticated successfully with payload:", authData);
    }
};

var args = {
    email: req.body.email,
    password: req.body.password,
    provider: req.body.provider
};

if (args.provider=="password") {
    ref.authWithPassword({email: args.email, password: args.password}, authHandler);
}
//Provider can be only facebook or twitter
else  {
    ref.authWithOAuthPopup(args.provider, authHandler); //Doesn't work
}

1 个答案:

答案 0 :(得分:1)

这很可能是浏览器使用弹出窗口或本地文件试图访问其未获得许可的资源的问题。您的代码可能没有任何问题,但您需要以某种方式处理此边缘情况。

有关此问题的解决方法,请参阅此处的文档:https://www.firebase.com/docs/web/guide/user-auth.html

  

TRANSPORT_UNAVAILABLE请求的登录方法在用户的浏览器环境中不可用。 Chrome for iOS,iOS预览窗格或本地的file://网址中不提供弹出窗口。重定向不适用于PhoneGap / Cordova或本地文件:// URL。

facebook的解决方法(与Twitter / Google登录相同,只是在下面的引号中交换名称)是使用重定向而不是弹出窗口的后备(假设您在这里使用弹出窗口):< / p>

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
// prefer pop-ups, so we don't navigate away from the page

ref.authWithOAuthPopup("google", function(error, authData) {
  if (error) {
    if (error.code === "TRANSPORT_UNAVAILABLE") {
      // fall-back to browser redirects, and pick up the session
      // automatically when we come back to the origin page
      ref.authWithOAuthRedirect("google", function(error) { /* ... */ });
    }
  } else if (authData) {
    // user authenticated with Firebase
  }
}
相关问题