GoogleWebComponents / google-signin

Google Sign-in web component
https://elements.polymer-project.org/elements/google-signin
Other
278 stars 88 forks source link

Add init event #137

Open nodirt opened 8 years ago

nodirt commented 8 years ago

There is no event in google-signin/google-singin-aware that is fired when gapi.auth2 is initialized. It makes really hard to use these elements in a static SPA.

I'd like to send iron-ajax requests to load actual page contents either (a) anonymously when the user is not signed in or (b) authenticated if the user is signed in. However, there is no way to tell whether google-signin* element is signing in in the background and I eventually will get an access token, or it is doing nothing because there is no cookie.

I tried to work around by forcing signin by calling signIn() in my ready() function, but it fails with an error because auth instance is not initialized at that time, and I don't know when to call it because there is no init event!

I cannot even work with gapi.auth2 directly, bypassing google-signin, because google-singin* takes full ownership of gapi.auth2 instance and initializes it itself when I set client-id.

Am I doing something wrong? Sending an authenticated request to load page contents seems to be a common usage scenario.