【问题标题】:How to remove a listener attached to auth0-lock?如何删除附加到 auth0-lock 的侦听器?
【发布时间】:2019-01-26 12:31:54
【问题描述】:

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));
  });
});

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

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

如何删除根据上述示例设置的侦听器?

【问题讨论】:

    标签: javascript auth0 auth0-lock


    【解决方案1】:

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

    我认为以下工作:

    lock.removeAllListeners('authenticated')
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-18
      • 1970-01-01
      • 2011-06-01
      • 2014-12-01
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      • 2018-04-26
      相关资源
      最近更新 更多