修复用户名+邀请码注册(无手机号)必现崩溃:Tinode.credential(null) 抛异常

现象:企业码注册流程走"仅用户名+邀请码,不填手机号"这条路径时,点"注册"必然抛出
原始 JS 报错"Cannot destructure property 'val' of 'meth' as it is null",直接
展示在错误提示条上,注册无法完成。

根因:auth-onboarding-view.jsx 的 Register 组件在没有手机号凭证、只有邀请码时,
把 cred_ 显式传成 null(没有可附加的凭证)。tinode-sdk 的 Tinode.credential(meth,...)
用 `typeof meth == 'object'` 判断参数是不是一个 {meth,val,resp,params} 对象,但
JS 里 `typeof null === 'object'` 也是 true,导致对 null 无条件解构,直接抛异常。
所有走"登录"分支的调用点传的从来都是"字段可能是 undefined 的对象",从未传过字面量
null,所以这个 bug 只在"用户名注册且没有手机号凭证"这一条路径上必现。

修法:cred_ 为空时不再调用 Tinode.credential(),直接把 cred 字段设为 undefined,
绕开 SDK 这个不处理 null 输入的缺陷,不改动 vendored 的 tinode-sdk 代码。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Your Name
2026-09-06 13:19:26 +08:00
co-authored by Claude Sonnet 5
parent fa2c6c2f07
commit eaafabe94f
+14 -1
View File
@@ -1565,8 +1565,21 @@ class TinodeWeb extends React.Component {
if (public_ && public_.photo && public_.photo.ref) {
attachments = [public_.photo.ref];
}
// cred_ is `null` on the username-only registration path (auth-onboarding-view.jsx's Register
// passes it literally as `null` when there's no phone credential to attach, only an invite
// code). tinode-sdk's Tinode.credential(meth, ...) checks `typeof meth == 'object'` to decide
// whether its first argument is really a single {meth,val,resp,params} object -- but
// `typeof null === 'object'` is true in JS, so it unconditionally destructures `{val, params,
// resp, meth} = meth` and crashes with a raw "Cannot destructure property 'val' of 'meth' as
// it is null" the moment it receives a real `null` (as opposed to an object with merely
// undefined fields, which every *login* call site here happens to always pass and which
// destructures fine). This made username-only registration (with or without a valid invite
// code -- client-side validation passes either way before reaching here) always throw and
// never send the {acc} message at all, with the raw JS error text leaking into the "注册"
// button's error banner. Not calling Tinode.credential() at all when there is nothing to
// wrap sidesteps the SDK's bug without patching vendored node_modules code.
return this.tinode.createAccountBasic(login_, password_,
{public: public_, tags: tags_, cred: Tinode.credential(cred_), attachments: attachments});
{public: public_, tags: tags_, cred: cred_ ? Tinode.credential(cred_) : undefined, attachments: attachments});
}).then(ctrl => {
if (ctrl.code >= 300 && ctrl.text == 'validate credentials') {
if (!TinodeWeb.navigateToCredentialsView(ctrl.params)) {