首页 > 解决方案 > 如何制作经过身份验证的请求firebase js

问题描述

我使用 django 作为后端并设置了身份验证系统。而在我的前端,我正在使用我的 firebase 实时数据库收听实时变化

const assignmentUpdateNotifications = () => {
    let ref =  database.ref('Assigned').child(userClass).child(userSection);
    ref.on('value', function(dataSnapshot){
        data = dataSnapshot
        doSomething(data)
    });
}

但是由于用户尚未通过身份验证,因此没有返回任何内容。

{
  "rules": {
    ".read": "auth.uid != null",
    ".write": "auth.uid != null"
  }
}

我无法更改我的规则,因为我不希望每个人都可以访问。此外,我不会在前端再次对用户进行身份验证。我有从 django 传递给 js 的用户 idToken。当我发出读取请求时,有没有办法可以使用/传递该令牌。

标签: javascriptfirebase-realtime-databasefirebase-authenticationfirebase-security

解决方案


推荐阅读