What could be causing the Google Sign-In functionality to fail in an Angular web application?

I'm currently working on implementing Google sign-in for my web app. I've been following this tutorial here. However, I'm facing an issue where the Google sign-in button is not appearing. I would like the authentication to happen at http://localhost:4200/home instead of http://localhost:4200.

This is how my home HTML looks:

<html>
<head>
        <script src="https://apis.google.com/js/platform.js" async defer></script>
        <meta name="google-signin-client_id" content="998210766859-ag7cijtb0md9cj6oj9nvqis5kk8g7929.apps.googleusercontent.com">
</head>
<body>

<br>
<a href="#" onclick="signOut();">Sign out</a>

<div class="g-signin2" data-onsuccess="onSignIn"></div>

<script>
  function signOut() {
    var auth2 = gapi.auth2.getAuthInstance();
    auth2.signOut().then(function () {
      console.log('User signed out.');
    });
  }
</script>

</body> 
</html> 

This is the related component.ts file:

import { Component, OnInit } from '@angular/core';
import { BlogService } from '../blog.service';
import { Blogpost } from '../blogpost';

@Component({
  selector: 'app-frontpage',
  templateUrl: './frontpage.component.html',
  styleUrls: ['./frontpage.component.css']
})

export class FrontpageComponent implements OnInit {
  public lis = [];
  public l1 ="siba";
  constructor(private servo:BlogService) { }

  ngOnInit(): void {
    this.servo.getblogs()
    .subscribe(data => this.lis = data);
  }

  onSignIn(googleUser) {
    var profile = googleUser.getBasicProfile();
    console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
    console.log('Name: ' + profile.getName());
    console.log('Image URL: ' + profile.getImageUrl());
    console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
  }

}

The issue I face is that when running the app, the sign-in button does not appear, only the sign-out anchor tag is visible.

Answer №1

If you're looking to incorporate social login functionality into your Angular project, consider giving the angularx-social-login package a try. You can find more information about it here. It's user-friendly and simple to integrate.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Isolating a type as a constant in Typescript within a .js file?

Within my .js configuration files, I have a tsconfig containing the property checkJs: true. A library called Terser includes the following type options: ecma: 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 Despite setting ecma: 2017 in my configuration file ...

My goal is to intentionally trigger an eslint error when importing a file from index.ts

Is there a way to enforce importing components from index.ts within the src/components directory using eslint rules or plugins? // index.ts (src/components/Forms) export { Input } from './Input'; export { CheckBox } from './CheckBox'; ...

Angular 9 does not include the mat-radio-group component within its known modules

After upgrading from Angular 2 to Angular 9, I encountered the following error: src/app/contact-list/contact-list.component.html:7:5 - error NG8001: 'mat-radio-group' is not a known element: 1. If 'mat-radio-group' is an Angular compo ...

No image is displayed when searching for a photo on Google Places

When calling the API to retrieve an image, instead of getting the actual image, I receive a link to an HTML page with the requested image. How do I get only the image itself? Here is the code snippet, where the "foto" parameter is the photo_reference obtai ...

Using async/await does not execute in the same manner as forEach loop

Here is a code snippet that I have been working with. It is set up to run 'one' and then 'two' in that specific order. The original code listed below is functioning correctly: (async () => { await runit('one').then(res ...

Instructions for including a class are ineffective

I am trying to dynamically add a class to a div based on two conditions. To achieve this, I have created a custom directive as shown below: import { Directive, HostBinding, Input } from '@angular/core'; @Directive({ selector: '[confirmdia ...

What is the reasoning behind an empty input value being considered as true?

I am facing an issue with the following code that is supposed to execute oninput if the input matches the answer. However, when dealing with a multiplication problem that equals 0, deleting the answer from the previous calculation (leaving the input empt ...

Using jQuery: When the API has loaded successfully, execute the specified function

As I dive into working with a search flight API, my goal is to configure some settings when the API loads. Below is the code snippet for loading the API: skyscanner.load('snippets', '1'); function main(){ var snippet=new skysc ...

Why aren't enums that can be derived supported?

Is there a way to create an enum that is a subset of another enum? Sometimes it would be useful to have an enum that is a subset of another Enum with the same values at run time but under a different name. Are there better ways to handle this scenario? ...

Utilizing Angular for Webcam Integration

After trying out this code snippet: <video autoplay playsinline style="width: 100vw; height: 100vh;"></video> <script> navigator.mediaDevices.getUserMedia({ video: { facingMode: 'user' } }) .then(stream =&g ...

Testing Angular: How to Unit-test HttpErrorResponse with custom headers using HttpClientTestingModule

In the code snippet below, I am attempting to find a custom header on error: login(credentials: Credentials): Observable<any> { return this.http.post(loginUrl, credentials) .pipe( catchError((httpErrorResponse: HttpErrorRespo ...

Determine the output type of a function in Typescript using an input value specified by an enum

I am currently saving settings to local storage and want to be able to input responses when retrieving (and possibly inserting) values from/to the storage. After researching, it seems that using function overloading is the best approach. Here is what I ha ...

Reference ngFor for Input Validation Template

I'm currently facing an issue with validating input fields within a *ngFor loop. I am struggling to create unique template references for each input field. Basically, I need all input fields to be required on submit unless at least one of them is fill ...

Is there another way to implement this method without having to convert snapshotChanges() into a promise?

When trying to retrieve cartIdFire, it is returning as undefined since the snapshot method is returning an observable. Is there a way to get cartIdFire without converting the snapshot method into a promise? Any workaround for this situation? private asyn ...

Slim and Angular2 htaccess configuration

I am encountering an issue with my htaccess file and could use some assistance. My setup includes an Angular2 app (single page client side app, index.html) and a slim-v3 PHP REST API (index.php). The Angular2 app interacts with the REST API, and I would id ...

An error has occurred in Node.js/Express.js: The path argument is missing and is required for res.sendFile

I have successfully uploaded my files using Multer to a specific directory. However, I am now facing an issue while trying to download the same files that are displayed in an HTML table with individual download options. Below is the code snippet: Node.j ...

Transferring multiple parameters between components using Navigate and ParamMap

My concern is that I'm unsure of how to pass multiple parameters through the component's route. I need to send two attributes. Is there a specific syntax required in defining the route? Below is my desired functionality for passing the attribut ...

"Endless loop conundrum in ngrx router

Currently, I am facing an issue while trying to integrate ngrx router-store into my application. After referencing the example app on GitHub, it seems that adding a `routerReducer` property to my application state and including the `routerReducer` from ngr ...

Creating an index signature in TypeScript without having to use union types for the values - a comprehensive guide

Is it possible to define an index signature with strict type constraints in TypeScript? interface Foo { [index: string]: number | string } However, I require the value type to be either number or string specifically, not a union of both types (number | ...

Using Angular/Typescript to interact with HTML5 Input type Date on Firefox (FF)

Are there any Angular/Typescript projects that are completely built without relying on third-party libraries? I am encountering problems with Firefox and IE11. It works fine on Chrome where the value can be read, but the calendar does not display when us ...