Angular :
<a (click)="handleGoogleLogin()"
class="btn btn-flex btn-outline btn-text-gray-700 btn-active-color-primary bg-state-light flex-center text-nowrap w-100">
<img alt="Logo" src="./assets/media/svg/brand-logos/google-icon.svg" class="h-15px me-3" />
Sign in with Google
</a>
Component:
handleGoogleLogin(): void {
this.authService.loginWithGoogle().subscribe(
(data) => {
const authToken = data.token;
localStorage.setItem('authToken', authToken);
},
(error) => {
console.error('Error while logging in with Google:', error);
}
);
}
SERVICE:
loginWithGoogle(): Observable<any> {
return this.http.get<any>(`${this.apiUrl}/auth/google/redirect`);
}
this is my error:
:4200/auth/login:1 Access to XMLHttpRequest at 'https://accounts.google.com/o/oauth2/v2/auth?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fapi%2Fauth%2Fgoogle%2Fredirect&scope=profile%20email&client_id=688590457392-ci81rp7df9au2r97gk4pgggljqqe31iu.apps.googleusercontent.com' (redirected from 'http://localhost:3000/api/auth/google/redirect') from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.