Skip to content

Commit

Permalink
Add sign out function & check for gapi.auth2 #43
Browse files Browse the repository at this point in the history
  • Loading branch information
CMenne committed Jun 25, 2018
1 parent b3d1182 commit 44a5e74
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions client/src/app/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,66 @@
import { Component, OnInit } from '@angular/core';
import { Observable } from "rxjs/Observable";

declare const gapi: any;
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})

export class LoginComponent implements OnInit {
simpleObservable = new Observable((observer) => {
this.checkGapi();
});

constructor() {
}

checkUserDetails() {
if (gapi.auth2) {
var googleAuth = gapi.auth2.getAuthInstance();
var googleUser = googleAuth.currentUser.get();
var profile = googleUser.getBasicProfile();

console.log('Auth is signed in: ' + googleAuth.isSignedIn.get());
console.log('User is signed in: ' + googleUser.isSignedIn());
console.log('Hosted Domain: ' + googleUser.getHostedDomain());
console.log('User has granted: ' + googleUser.getGrantedScopes());
console.log('User name: ' + profile.getName());
console.log('User email: ' + profile.getEmail());
console.log('User image: ' + profile.getImageUrl());

} else {
console.log('gapi.auth2 is undefined');
}
}

signOut() {
if (gapi.auth2) {
gapi.auth2.getAuthInstance().signOut();
} else {
console.log('cant sign out, no gapi');
}
}

sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

constructor() { }
async checkGapi() {
await this.sleep(100);

ngOnInit() {
if (gapi.auth2 != undefined) {
console.log('gapi.auth2 is initialized');
return true;
} else {
console.log('gapi.auth2 is undefined');
this.checkGapi();
}
}

}
ngOnInit() {
this.simpleObservable.subscribe();
}

}

0 comments on commit 44a5e74

Please sign in to comment.