小编Tre*_*ent的帖子

Handlebars模板功能中未定义的Meteor用户对象

模板上的以下简单函数通常会失败,因为user对象未定义,即使我已登录:

Template.hello.userData = function() {
  var user = Meteor.users.findOne(Meteor.userId());
  return user.emails[0].address;
};
Run Code Online (Sandbox Code Playgroud)

它很容易复制:

  • 在命令行上:
    • meteor创建测试用户
    • cd测试用户
    • meteor add accounts-password
    • meteor add accounts-ui
  • 编辑test-user.js并将'userData'代码(上面)添加到isClient块中
  • 编辑test-user.html并在'hello'模板中添加:{{loginButtons}} {{userData}}
  • 转到应用程序并创建一个帐户,该帐户会让您登录并在控制台中收到错误消息: Uncaught TypeError: Cannot read property 'emails' of undefined

阴险的是"通常"部分:它有时会成功,因此可能存在竞争条件......并且可能是依赖项被加载的顺序.

我实际上是在一个更复杂的应用程序中点击这个,试图访问我登录用户的"profile"属性(存在,我保证).它在不同的浏览器中提供略有不同的错误消息 这是Chrome中的堆栈跟踪:

Exception from Deps recompute: TypeError: Cannot read property 'profile' of undefined
    at Object.Template.workbook.owner (http://localhost:3000/client/client.js?153b3db62478692678dd9fdf9f1a9dd0b6b6a76e:130:21)
    at apply (http://localhost:3000/packages/handlebars.js?c2b75d49875b4cfcc7544447aad117fd81fccf3b:276:24)
    at invoke (http://localhost:3000/packages/handlebars.js?c2b75d49875b4cfcc7544447aad117fd81fccf3b:301:12)
    at http://localhost:3000/packages/handlebars.js?c2b75d49875b4cfcc7544447aad117fd81fccf3b:365:30
    at Object.Spark.labelBranch (http://localhost:3000/packages/spark.js?3a050592ceb34d6c585c70f1df11e353610be0ab:1171:14)
    at branch (http://localhost:3000/packages/handlebars.js?c2b75d49875b4cfcc7544447aad117fd81fccf3b:355:20)
    at http://localhost:3000/packages/handlebars.js?c2b75d49875b4cfcc7544447aad117fd81fccf3b:364:18
    at Array.forEach (native)
    at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?13ab483e8a3c795d9991577e65e811cd0b827997:130:11)
    at template (http://localhost:3000/packages/handlebars.js?c2b75d49875b4cfcc7544447aad117fd81fccf3b:358:7) debug.js:41
Exception …

meteor

3
推荐指数
1
解决办法
1885
查看次数

为什么 openssl 每次使用“source”“验证”都会成功,但在脚本中却有 80% 的时间失败?

如果我每次都可以运行以下脚本,source ./script.sh但如果直接将其作为 执行,则大约 80% 的情况会失败./script.sh

#!/bin/bash
signing_input="Hi."
signature=$(echo -n "$signing_input" | openssl dgst -sha256 -sign private.pem)
echo -n "$signing_input" | openssl dgst -sha256 -verify public.pem -signature <(echo -n "$signature")
Run Code Online (Sandbox Code Playgroud)

因此,如果我“获取”该内容或逐行运行,我总是会得到:Verified OK

...但是如果我在脚本中运行它,我通常但并不总是得到:Error verifying data

如果我先将签名保存到文件中,我会得到相同的结果。

.pem这样生成文件:

openssl ecparam -name secp256k1 -genkey -noout -out private.pem
openssl ec -in private.pem -pubout -out public.pem
Run Code Online (Sandbox Code Playgroud)

...我是否每次重复使用它们或重新生成它们并不重要。

我在 Mac M1 上运行 iTerm2 和 zsh。

bash openssl

0
推荐指数
1
解决办法
47
查看次数

标签 统计

bash ×1

meteor ×1

openssl ×1