Skip to content

Instantly share code, notes, and snippets.

@jon-dearaujo
Created February 2, 2018 02:08
Show Gist options
  • Select an option

  • Save jon-dearaujo/2e68892d738649f34106713490e16720 to your computer and use it in GitHub Desktop.

Select an option

Save jon-dearaujo/2e68892d738649f34106713490e16720 to your computer and use it in GitHub Desktop.
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
const gapi = window['gapi'];
const SCOPE = 'email profile https://www.googleapis.com/auth/drive.metadata.readonly';
if (gapi) {
new Promise((resolve, reject) => {
gapi.load('client:auth2', {
callback: () => {
console.log('client:auth2 loaded');
gapi.client.init({
clientId: '719627788647-ifgm8v5sghj4u6a1us2b10lplbq3pfe6.apps.googleusercontent.com',
scope: SCOPE
}).then(() => {
if (gapi.auth2.getAuthInstance().isSignedIn.get()) {
gapi.client.load('drive', 'v3', () => {
gapi.client.drive.files.list({
pageSize: 10,
fields: 'nextPageToken, files(id, name)'
}).then((r) => {
console.log(r);
resolve();
})
})
} else {
console.log('nop! not signed in at all');
gapi.auth2.getAuthInstance().signIn({
scope: SCOPE,
ux_mode: 'redirect',
redirect_uri: 'http://localhost:4200'
}).then(() => console.log('Yay! now properly signed in'), () => console.log('Nop! not signed in yet'));
}
})
}, onerror: () => {
throw new Error('Error while loading client:auth2');
}
})
}).then(() => {
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
})
} else {
throw new Error('gapi not ready yet');
}
@jon-dearaujo
Copy link
Author

Using Drive api just to ensure it is properly loading user data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment