【发布时间】:2021-12-20 10:52:53
【问题描述】:
我正在尝试设置 Pusher 以接收来自我的服务器的推送通知。我已经阅读了文档并按照说明进行操作,但我收到了这个错误,我不知道如何解决。如果你帮我解决它,它就像是一份早期的圣诞礼物。
这是我的客户端代码:
const beamsClient = new PusherPushNotifications.Client({
instanceId: 'XXXXX-XXXX-XXXXX-XXXX',
});
const beamsTokenProvider = new PusherPushNotifications.TokenProvider({
url: "/Account/BeamsAuth/",
});
var currentUserId = `@User.Identity.GetUserId()`;
beamsClient.start()
.then(() => beamsClient.setUserId(currentUserId, beamsTokenProvider))
.then(() => beamsClient.addDeviceInterest('WaitingForRide'))
.then(() => beamsClient.getDeviceInterests())
.then((interests) => console.log("Current interests: ", interests))
.then(() => console.log('Successfully registered and subscribed!'))
.catch(console.error);
这是我的服务器代码:
这是我在浏览器控制台上看到的错误:
TypeError: Cannot read properties of null (reading 'token')
at Client._callee14$ (push-notifications-cdn.js:2102)
at tryCatch (push-notifications-cdn.js:82)
at Generator.invoke [as _invoke] (push-notifications-cdn.js:308)
at Generator.prototype.<computed> [as next] (push-notifications-cdn.js:134)
at asyncGeneratorStep (push-notifications-cdn.js:770)
at _next (push-notifications-cdn.js:792)
我很肯定我已经正确实施了令牌获取过程,但我似乎无法克服这个错误。这是一个总的曲线球。
我真的不知道在这里做什么。我尝试研究这个特定的错误,但没有得到任何回报。任何想法都表示赞赏。
【问题讨论】:
-
@KenLee 感谢您的回复。那部分有效。我已经在 API 端检查了用户 ID,它实际上确实将用户 ID 从客户端成功发布到服务器。我将发布一张图片来证明这一点。等一下!
-
@KenLee 是的,就是这样。这里的文档:pusher.com/docs/beams/concepts/authenticated-users/… 说您应该自己实现令牌检索过程。我在上面添加了更多细节。
-
@KenLee 我不确定为什么客户端的javascript代码说它无法读取令牌。从我上面粘贴的图片来看,服务器端代码显然返回了一个令牌字符串。控制台只提供我上面粘贴的错误。所以我只能摸不着头脑。