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-
如何删除按照上述示例设置的监听器?
最佳答案
我遇到了同样的问题,不知道为什么没有关于如果您出于某种原因需要销毁锁定小部件或重置它时如何删除监听器的文档。
我认为以下方法可行:
lock.removeAllListeners('authenticated')
如果你想删除所有的监听器,只需省略'authenticated'作为参数
关于javascript - 如何删除附加到 auth0-lock 的监听器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51929707/