# angular2-google-login

> Google login with Angular 2

Latest version **1.0.9** (published 2017-05-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install angular2-google-login
pnpm add angular2-google-login
yarn add angular2-google-login
bun add angular2-google-login
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2017-05-12 |
| First published | 2017-05-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+18 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Rudraksh Pathak |
| Maintainers | rudrakshpathak |
| Keywords | angular2-google-login, angular2-google-authentication |

## Links

- npm: https://www.npmjs.com/package/angular2-google-login
- Repository: https://github.com/rudrakshpathak/angular2-google-login
- Homepage: https://github.com/rudrakshpathak/angular2-google-login#readme
- Issues: https://github.com/rudrakshpathak/angular2-google-login/issues
- npm.io page: https://npm.io/package/angular2-google-login

## Dependencies (5)

- [core-js](https://npm.io/package/core-js.md) ^2.4.1
- [zone.js](https://npm.io/package/zone.js.md) ^0.7.2
- [@angular/core](https://npm.io/package/@angular/core.md) ^2.3.1
- [@angular/common](https://npm.io/package/@angular/common.md) ^2.3.1
- [@angular/compiler](https://npm.io/package/@angular/compiler.md) ^2.3.1

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 1.0.9 (latest) — 2017-05-12
- 1.0.8 — 2017-05-12
- 1.0.7 — 2017-05-09
- 1.0.6 — 2017-05-09
- 1.0.5 — 2017-05-09
- 1.0.4 — 2017-05-09
- 1.0.3 — 2017-05-09
- 1.0.2 — 2017-05-09
- 1.0.1 — 2017-05-09

## README

# Angular 2 Google Login
This is a sample app showing how we can login using Google authentication in Angular2.

You can visit npm for more info on [angular2-google-login package](https://www.npmjs.com/package/angular2-google-login)

[![version](https://img.shields.io/badge/version-v1.0.9-orange.svg)]()
[![npm](https://img.shields.io/npm/v/npm.svg)]()
[![npm](https://img.shields.io/npm/l/express.svg)]()
[![PyPI](https://img.shields.io/badge/status-stable-brightgreen.svg)]()

### To use the package in your app
Run `npm install angular2-google-login`

### Import Package 
Import this package where you want to use Google authentication service. 
```javascript
import { AuthService, AppGlobals } from 'angular2-google-login';
```

### Providers
Supply the provider.
```javascript
providers: [AuthService];
```

### Constructor 
```javascript
constructor(private _googleAuth: AuthService){}
```

### Set your Secret Google Client ID
Set your Google client Id. preferably in `ngOnInit()` interface.
```javascript
AppGlobals.GOOGLE_CLIENT_ID = 'SECRET_CLIENT_ID';
```

### Using the Google Login service 
Use this code snippet to call the Google authentiation service. You can call it in a function triggered by a button click or in your desired event.
```javascript
this._googleAuth.authenticateUser(()=>{
      //YOUR_CODE_HERE
    });
```

### Using fetched Google account details
In the package, `localstorage` is used to hold the data -
```javascript
localStorage.setItem('token', userDetails.getAuthResponse().id_token);
localStorage.setItem('image', profile.getImageUrl());
localStorage.setItem('name', profile.getName());
localStorage.setItem('email', profile.getEmail());
```
Alternatively, you can tweak the code and create an object that you can return to do post operation after successful login -
```javascript
result = {
   token: userDetails.getAuthResponse().id_token,
   name: profile.getName(),
   image: profile.getImageUrl(),
   email: profile.getEmail(),
 };
 return result;
```

### Logout user
```javascript
this._googleAuth.userLogout(()=>{
      //YOUR_CODE_HERE
    });
```

### Development server
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`.

---
### Known Issue
You might get error : `gapi is not defined`
It is because the service component may get loaded before `gapi` is declared. Make sure you handle it when you use the service.

SUGGESTION : Use `AfterViewInit` interface.

---
_Source: https://npm.io/package/angular2-google-login · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
