1

I'm trying to setup the ability for the Authenticated User to manage the OAuth accounts they have linked. Here's the code I'm using in my Angular Component:

linkGoogle(): void {
 debugger; // this pauses 1st
 const googleAuthButton = document.createElement('div');
 googleAuthButton.setAttribute('id', 'google-button');
 // Inject Google button dynamically
 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; // this never pauses
 // Use the new CustomerService method
 this.customerService.linkGoogleAccount(idToken).subscribe({
 next: () => {
 this.snackBar.open('Google account linked successfully!', 'Close', {
 duration: 3000,
 });
 document.body.removeChild(googleAuthButton); // Cleanup
 this.authService.initializeAuth().subscribe(); // Refresh current user
 },
 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();
 }

When I invoke this function I can see the debugger; statements pause but not the one that I have set inside the defined callback function.

I expect the callback method to be invoked so I can see the token and manage the linked account.

asked Jan 19, 2025 at 0:39
1

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.