将Firebase身份验证令牌发送到Node.js服务器

时间:2019-07-02 21:08:08

标签: javascript node.js firebase firebase-authentication http-headers

我想让客户端通过前端使用Firebase登录。稍后,我想发送验证他已登录到我的服务器的令牌,以便我可以在数据库中检查有关他的某些信息。例如:如果他为特定课程付费。

firebase文档未提供有关如何将其发送到我自己的服务器的实际代码:

firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idToken) {
  // Send token to your backend via HTTPS
  // ...
}).catch(function(error) {
  // Handle error
});

所以,我正在寻找一个想法,或者最好是一些有关如何随每个请求将令牌发送到服务器的代码。

1 个答案:

答案 0 :(得分:1)

很多方法可以做到。我喜欢使用Axios https://github.com/axios/axios

axios.post('/your-endpoint', {
    token: your-token
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
相关问题