I would use a shared service for this.
interface User {
phone: string;
// whatever else
}
LoginPage {
constructor(private _auth: AuthService, private _uisvc: UserInfoService, private _nav: NavController) {}
login(): void {
this._uisvc.getUserInfo(this.form.whatever).subscribe((ui) => {
this._auth.user = ui;
this._nav.push(DashboardPage);
});
}
}
AnyOtherPage {
constructor(private _auth: AuthService) {}
doSomething(): void {
relyOn(this._auth.user);
}
}
AuthService {
user: User;
}
UserInfoService {
constructor(private _http: Http) {}
getUserInfo(whatever): Observable<User> {
return this._http.get(url + whatever).map(rsp => rsp.json());
}
}
My personal preference when dealing with login/logout is to handle it all in a subscription in the app component, so I never deal with the NavController
at all. Details here if you want to consider that approach.