Angular中google.accounts.id.initialize的回调函数未触发问题求助
Angular中google.accounts.id.initialize的回调函数未触发问题求助
我正在做Angular项目的功能开发,想要实现让已登录用户能够管理自己关联的OAuth账号,目前在处理Google账号关联的部分。下面是我组件里的实现代码:
linkGoogle(): void { debugger; // 这里能正常触发断点 const googleAuthButton = document.createElement('div'); googleAuthButton.setAttribute('id', 'google-button'); // 动态注入Google按钮 document.body.appendChild(googleAuthButton); const client = google.accounts.id; client.initialize({ client_id: environment.googleClientId, callback: (response: any) => { const idToken = response.credential; console.log('Google Sign-In callback triggered:', response); debugger; // 这个断点完全没触发 // 调用新的CustomerService方法 this.customerService.linkGoogleAccount(idToken).subscribe({ next: () => { this.snackBar.open('Google account linked successfully!', 'Close', { duration: 3000, }); document.body.removeChild(googleAuthButton); // 清理元素 this.authService.initializeAuth().subscribe(); // 刷新当前用户信息 }, error: (err) => { console.error('Error linking Google account:', err); this.snackBar.open('Failed to link Google account.', 'Close', { duration: 3000, }); }, }); }, auto_select: false, cancel_on_tap_outside: true, }); console.log('Client initialized:', client); client.prompt(); }
现在遇到了问题:当我调用这个linkGoogle函数时,开头的debugger能正常触发断点暂停,但callback函数里的那个debugger完全没有反应,控制台也看不到回调里的日志输出。
我本来预期这个callback方法会被正常调用,这样我就能拿到返回的token,继续完成Google账号关联的后续逻辑了。
备注:内容来源于stack exchange,提问作者Ian Tunbridge
相关产品推荐
相关产品推荐

