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

Change detection after auth iframe #47

Closed
vitto-moz opened this issue Mar 13, 2018 · 12 comments
Closed

Change detection after auth iframe #47

vitto-moz opened this issue Mar 13, 2018 · 12 comments

Comments

@vitto-moz
Copy link

vitto-moz commented Mar 13, 2018

after auth iframe appears - component loses control of change detection.
Changes can be applied only through changeDetector

I use NgRx so my code for authorization is next (NgRx Effects):

@Effect()
tryLogin = this.actions$
  .ofType(AuthActionTypes.TRY_LOGIN)
  .switchMap(() => this.signIn())
  .switchMap(result => of(result ? new LoginSuccess() : new LoginFailure()))

@Effect()
loginSuccess = this.actions$
  .ofType(AuthActionTypes.LOGIN_SUCCESS)
  .switchMap((): Observable<RouterActionType> => of(new RouterActions.Go({path: ['/calendar']})))

private signIn(): Observable<boolean> {
  return this.googleAuth.getAuth()
    .switchMap(auth => {
      return fromPromise(auth.signIn())
    })
    .map((res: GoogleUser) => {
      this.signInSuccessHandler(res)
      return true
    })
    .catch( (err) => {
      console.error('ERROR: ', err);
      return of(false)
    })
}

private signInSuccessHandler(res: GoogleUser) {
  this.user = res;
  sessionStorage.setItem(
    this.SESSION_STORAGE_KEY, res.getAuthResponse().access_token
  );
}

How sholuld I use library to avoid this behavior, thanks!

@rubenCodeforges
Copy link
Owner

i think you need ngZone https://dzone.com/articles/understanding-ngzone

@vitto-moz
Copy link
Author

wrap some code in this.zone.run(() => res.callback()) made changes - but still have issue
what should I wrap in case on auth2...?
It seems here is enough of zone.run =)

 private signIn(): Observable<boolean> {
    return this.zone.run(() => this.googleAuth.getAuth()
      .switchMap(auth => {
        return fromPromise(
          this.zone.run(() => auth.signIn())
        )
      })
      .map((res: GoogleUser) => {
        this.zone.run(() => this.signInSuccessHandler(res))
        return true
      })

@rubenCodeforges
Copy link
Owner

@vitto-moz maybe my example project can help you out , this is the userService from it https://github.com/rubenCodeforges/ng-gapi/blob/feature/example-project/examples/src/app/common/user/UserService.ts

@rubenCodeforges
Copy link
Owner

rubenCodeforges commented Mar 30, 2018

@vitto-moz since you didnt responde , i assume it helped , im closing this

@vitto-moz
Copy link
Author

vitto-moz commented Mar 30, 2018

@rubenCodeforges yes, your hint was helpful, thanks.
Want to add for those who use NgRx in their projects
there is a helpful method for returning to Angular Zone
here is a link to the comment I wrote
angular/zone.js#830 (comment)

@rubenCodeforges
Copy link
Owner

@vitto-moz nice one , thanks !

@vitto-moz
Copy link
Author

Hi, @rubenCodeforges , once again :)
I want to reveal situation with losing angularZone context in our local meetUp, but I don't understand the entire situation - why it happens :(
Please, if you have any idea, share them with me. Thanks!

@rubenCodeforges
Copy link
Owner

@vitto-moz hey , mmm its hard to tell for sure .
How about to schedule a meet(hangout) ?

@vitto-moz
Copy link
Author

@rubenCodeforges, ok, great, what time do you prefer, which timezone?
here is my mail
v.mozharovsky@gmail.com

@rubenCodeforges
Copy link
Owner

@vitto-moz im in GMT+2 do you have telegram ?

@vitto-moz
Copy link
Author

yep, I have an account. how to share it with you, by phone number?

@rubenCodeforges
Copy link
Owner

@vitto-moz ill send you my number by email

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

No branches or pull requests

2 participants