该问题的意思是,使用Auth0.js时,浏览器可能会出现跨源策略限制,阻止了window.closed()方法的调用。解决这个问题的方法是在注册Auth0应用程序时设置正确的跨源策略。
以下是一个示例代码,演示如何设置跨源策略以解决该问题:
const auth0 = new auth0.WebAuth({
domain: 'YOUR_DOMAIN.auth0.com',
clientID: 'YOUR_CLIENT_ID',
redirectUri: 'https://YOUR_APP/callback',
responseType: 'token id_token',
useRefreshTokens: true,
leeway: 60,
crossOriginVerification: 'none', // 设置Cross-Origin-Opener-Policy策略为None
});
auth0.login({
realm: 'Username-Password-Authentication',
username: 'user@example.com',
password: 'password',
}, (err, authResult) => {
if (err) {
// handle error
} else {
console.log(authResult);
}
});