如何删除附加到 auth0-lock 的侦听器?

How to remove a listener attached to auth0-lock?

Auth0-lock 文档提供了一个将侦听器附加到身份验证状态更改事件的示例:

https://auth0.com/docs/libraries/lock/v11#2-authenticating-and-getting-user-info

// Listening for the authenticated event
lock.on("authenticated", function(authResult) {
  // Use the token in authResult to getUserInfo() and save it to localStorage
  lock.getUserInfo(authResult.accessToken, function(error, profile) {
    if (error) {
      // Handle error
      return;
    }

    document.getElementById('nick').textContent = profile.nickname;

    localStorage.setItem('accessToken', authResult.accessToken);
    localStorage.setItem('profile', JSON.stringify(profile));
  });
});

API Auth0 Lock v11 参考提供了有关 on 支持的事件类型的更多详细信息,但是没有关于删除侦听器的主题:

https://auth0.com/docs/libraries/lock/v11/api#on-

如何删除按照上述示例设置的侦听器?

我遇到了同样的问题,不知道为什么没有关于如果您出于某种原因需要销毁锁定小部件或将其重置时如何删除侦听器的文档。

我认为以下作品:

lock.removeAllListeners('authenticated')

如果要删除所有监听器,只需省略 'authenticated' 作为参数