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

How Access currentUserData after page reload #253

Closed
Paktusin opened this issue May 22, 2017 · 2 comments
Closed

How Access currentUserData after page reload #253

Paktusin opened this issue May 22, 2017 · 2 comments

Comments

@Paktusin
Copy link

Hi. How can I subscribe currentUserData? After page reload, Validating user and then I need read userData but onInit method curentuserData is undefined. if on init I call validatetoken() it will be call twice.

import {Component, OnInit} from '@angular/core';
import {AppDataService} from './app.data.service';
import {Angular2TokenService, AuthData, UserData} from 'angular2-token';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
  selBrand;
  selModel;
  selBack;
  signedIn : boolean = false;
  currentUser : UserData;

  constructor(public  dataService: AppDataService,
              private _tokenService: Angular2TokenService) {
    this._tokenService.init({
      signInPath:'/auth/sign_in',
      registerAccountPath:'/auth',
      validateTokenPath:'/auth/validate_token',
      signOutPath:'/auth/sign_out',
      resetPasswordPath:'/auth/password',
      oAuthPaths: {
        vkontakte:'auth/vkontakte'
      },
    });
  }

  ngOnInit() {
    this.dataService.selBrand.subscribe((x) => this.selBrand = x);
    this.dataService.selModel.subscribe((x) => this.selModel = x);
    this.dataService.selBack.subscribe((x) => this.selBack = x);

    this.signedIn = this._tokenService.userSignedIn();
    this.currentUser = this._tokenService.currentUserData;
  }


  logOut() {
    this._tokenService.signOut().subscribe(()=>
      this.signedIn = this._tokenService.userSignedIn())
  }

  logIn(){
    this._tokenService.signInOAuth('vkontakte').subscribe(
      res => {
        this.signedIn = this._tokenService.userSignedIn();
        //console.log(res);
      },
    error => console.log(error)
    )
  }
}
@neroniaky
Copy link
Owner

Please see #134.

@Paktusin
Copy link
Author

Thanks. I hope init function will be Observable soon

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