Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gapi: attempts to signIn/signOut lead to "TypeError: cannot read property 'postMessage' of null" #238

Closed
Eljoy opened this issue Aug 26, 2016 · 9 comments
Labels

Comments

@Eljoy
Copy link

Eljoy commented Aug 26, 2016

After using ui-router's $state.reload() to update current state, any attempts to GoogleAuth.signIn/GoogleAuth.signOut lead to
"TypeError: Cannot read property 'postMessage' of null at NU"

@devravi
Copy link

devravi commented Sep 2, 2016

Facing same issue when calling .signOut () and calling gapi.auth2.getAuthInstance().currentUser.get().reloadAuthResponse();

@TMSCH TMSCH added the auth label Feb 16, 2017
@TMSCH
Copy link
Contributor

TMSCH commented Feb 16, 2017

@Eljoy @devravi gapi.auth2 relies on an IFrame to sign in and sign out users. If your application recreates the entire content within <body> tags, the IFrame can be removed and this would happen.
Could you confirm this is not the case? You could inspect the content of <body> after reloading the state. Otherwise, please provide a minimal snippet of code to reproduce the issue.

@TMSCH
Copy link
Contributor

TMSCH commented Apr 13, 2017

@Eljoy @devravi could you update this thread with more information? Thanks!

@Eljoy
Copy link
Author

Eljoy commented May 15, 2017

@TMSCH Here is the simplest code one can use to verify the described issue. Click "Sign Out" button and check out the console, to see an error "Uncaught TypeError: Cannot read property 'postMessage' of null". https://plnkr.co/edit/oFcRee13CynUC7LtPERv?p=preview

Thanks!

@TMSCH
Copy link
Contributor

TMSCH commented May 15, 2017

@Eljoy thanks for providing the snippet! The issue is the one I expected and mentioned in my previous comment. The ng-app being on <body>, it re-renders the entire content and remove the IFrame used by gapi.auth2. If I change to:

<body>
  <div  ng-app="app" ui-view></div>
</body>

The issue does not happen anymore as the IFrame is preserved. Would that solve your problem?

@Eljoy
Copy link
Author

Eljoy commented May 16, 2017

@TMSCH Yes, thanks! The solution turned out to be so simple :)

@Eljoy Eljoy closed this as completed May 16, 2017
@TMSCH
Copy link
Contributor

TMSCH commented May 16, 2017

You're welcome! Glad you got it to work!

@truonglocbinh
Copy link

@TMSCH I have same problem with error " Cannot read property 'postMessage' of null". I create a page login , when I click login button it will authorize and redirect to home page. But when I logout I redirect to sign in page , but I click login button, it doesn't working . I need refresh page and it work well. So i dont use any clients js such as react or angular js. I use ruby on rails as server . Please help me if you can .Thank so much

prasmussen added a commit to prasmussen/vevapp that referenced this issue Feb 4, 2019
gapi.auth2 relies on an IFrame to sign in and sign out users.
ref. google/google-api-javascript-client#238 (comment)
@Arjun99
Copy link

Arjun99 commented Apr 11, 2020

I have the same problem with error "Cannot read property 'postMessage' of null" when i try to signin using gapi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants