无法读取未定义的属性“代码”,解码Firebase ID令牌失败

带围巾

我约有5%的请求间歇性地收到此错误,但我不确定为什么。似乎大多数时候都可以使用,但我想将其提高到100%。

{"name":"myapp","hostname":"worker-844ddfbc9f-ntlmz","pid":18,"level":50,
"err":"[Throws: Cannot read property 'code' of undefined]",
"msg":"Context creation failed: Decoding Firebase ID token failed. Make sure you passed the entire string JWT which represents an ID token. See https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token.",
"time":"2020-02-12T02:16:33.538Z","v":0}
TypeError: Cannot read property 'code' of undefined
    at FirebaseAuthError.get [as code] (/app/node_modules/firebase-admin/lib/utils/error.js:51:35)
    at FirebaseAuthError.FirebaseError.toJSON (/app/node_modules/firebase-admin/lib/utils/error.js:67:24)
    at JSON.stringify (<anonymous>)
    at prettyJSONStringify (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:257:17)
    at throwHttpGraphQLError (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:26:42)
    at Object.<anonymous> (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:66:28)
    at Generator.next (<anonymous>)
    at fulfilled (/app/node_modules/apollo-server-core/dist/runHttpQuery.js:4:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)

客户

const authLink = setContext(async (_, { headers }) => {
    let token;
    if (firebase.auth().currentUser) {
        token = await firebase.auth().currentUser.getIdToken();
    }
    return {
        headers: {
            ...headers,
            authorization: `Bearer ${token}`,
        },
    };
});

服务器

            let token = req.headers.authorization;

            if (!token || !token.length) {
                console.log('no token');
            }

            token = token.split('Bearer ')[1];

            // validate JWT and pluck user id
            const { uid } = await firebase.auth().verifyIdToken(token);

            // find the user based on id
            const user = await firebase.auth().getUser(uid);
克鲁姆凯夫

您的客户端代码将生成授权标头,Bearer undefined如果标头firebase.auth().currentUser为false。该授权标头将不会导致no token登录到服务器代码中(其长度为16)。服务器代码将在运行时失败firebase.auth().verifyIdToken('undefined')

您需要阻止客户端发送请求(如果firebase.auth().currentUser错误),或者捕获服务器代码中的未定义令牌。

注意:在模板字符串中使用未定义的变量会导致字符串“未定义”(不是空字符串)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法读取未定义的属性“ id”

来自分类Dev

Firebase 函数:类型错误:无法读取未定义的属性“user_id”

来自分类Dev

失败:无法读取未定义的属性“全部”

来自分类Dev

React构建失败:无法读取未定义的属性“名称”

来自分类Dev

失败:无法读取未定义的属性“ getWebElements”

来自分类Dev

灰烬路线:无法读取未定义的属性“ id”

来自分类Dev

guildBanAdd无法读取未定义的属性“ id”

来自分类Dev

UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ id”

来自分类Dev

Gatsby TypeError-无法读取未定义的属性“ id”

来自分类Dev

MERN-TypeError:无法读取未定义的属性“ id”

来自分类Dev

删除时出错:无法读取未定义的属性“ id”

来自分类Dev

Serverless:“ errorMessage”:“无法读取未定义的属性” id“,

来自分类Dev

Angular Material TypeError:无法读取未定义的属性“ id”

来自分类Dev

用户注销后无法读取未定义的属性“ _id”

来自分类Dev

UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ id”

来自分类Dev

guildBanAdd无法读取未定义的属性“ id”

来自分类Dev

无法读取未定义的属性“ id”。表示

来自分类Dev

JWT-TypeError:无法读取未定义的属性“id”

来自分类Dev

Karma + ui路由器失败:无法读取未定义的属性“ isDefined”

来自分类Dev

ReactJS失败,并显示错误“无法读取未定义的属性'map'”

来自分类Dev

失败:无法读取未定义的属性“ setValue”用于登录测试

来自分类Dev

如何修复执行失败:TypeError:无法从未定义中读取属性“ 0”?

来自分类Dev

由于类型错误,离子包构建 android 失败:无法读取未定义的属性“长度”

来自分类Dev

React Native 测试失败:“TypeError:无法读取未定义的属性‘fs’”

来自分类Dev

使用表的 Gherkin 测试失败并显示错误“无法读取未定义的属性‘粗体’”

来自分类Dev

反应:警告:道具类型失败:无法读取未定义的属性“应用”

来自分类Dev

Angular2-TypeError:无法读取(Typescript)中未定义的属性'Id'

来自分类Dev

AngularJS + Fullcalendar发送错误TypeError:无法读取未定义的属性'__id'

来自分类Dev

使用猫鼬findOneandUpdate时无法读取未定义的属性'_id'

Related 相关文章

  1. 1

    无法读取未定义的属性“ id”

  2. 2

    Firebase 函数:类型错误:无法读取未定义的属性“user_id”

  3. 3

    失败:无法读取未定义的属性“全部”

  4. 4

    React构建失败:无法读取未定义的属性“名称”

  5. 5

    失败:无法读取未定义的属性“ getWebElements”

  6. 6

    灰烬路线:无法读取未定义的属性“ id”

  7. 7

    guildBanAdd无法读取未定义的属性“ id”

  8. 8

    UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ id”

  9. 9

    Gatsby TypeError-无法读取未定义的属性“ id”

  10. 10

    MERN-TypeError:无法读取未定义的属性“ id”

  11. 11

    删除时出错:无法读取未定义的属性“ id”

  12. 12

    Serverless:“ errorMessage”:“无法读取未定义的属性” id“,

  13. 13

    Angular Material TypeError:无法读取未定义的属性“ id”

  14. 14

    用户注销后无法读取未定义的属性“ _id”

  15. 15

    UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ id”

  16. 16

    guildBanAdd无法读取未定义的属性“ id”

  17. 17

    无法读取未定义的属性“ id”。表示

  18. 18

    JWT-TypeError:无法读取未定义的属性“id”

  19. 19

    Karma + ui路由器失败:无法读取未定义的属性“ isDefined”

  20. 20

    ReactJS失败,并显示错误“无法读取未定义的属性'map'”

  21. 21

    失败:无法读取未定义的属性“ setValue”用于登录测试

  22. 22

    如何修复执行失败:TypeError:无法从未定义中读取属性“ 0”?

  23. 23

    由于类型错误,离子包构建 android 失败:无法读取未定义的属性“长度”

  24. 24

    React Native 测试失败:“TypeError:无法读取未定义的属性‘fs’”

  25. 25

    使用表的 Gherkin 测试失败并显示错误“无法读取未定义的属性‘粗体’”

  26. 26

    反应:警告:道具类型失败:无法读取未定义的属性“应用”

  27. 27

    Angular2-TypeError:无法读取(Typescript)中未定义的属性'Id'

  28. 28

    AngularJS + Fullcalendar发送错误TypeError:无法读取未定义的属性'__id'

  29. 29

    使用猫鼬findOneandUpdate时无法读取未定义的属性'_id'

热门标签

归档