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锁v11的API参考提供了有关on支持的事件类型的更多详细信息,但没有提供有关删除监听程序的内容:
https://auth0.com/docs/libraries/lock/v11/api#on-
如何删除按照上述示例设置的监听器?
发布于 2019-01-23 00:41:46
我也遇到过同样的问题,我不知道为什么如果出于某种原因需要销毁锁小部件或重置它时,没有关于如何删除侦听器的文档。
我认为下面的方法是可行的:
lock.removeAllListeners('authenticated')如果要删除所有监听器,只需省略'authenticated‘作为参数
https://stackoverflow.com/questions/51929707
复制相似问题