# Reload View after Login (pop)

**URL:** <https://forum.ionicframework.com/t/reload-view-after-login-pop/80221>\
**Category:** ionic-v3\
**Created:** [February 20, 2017, 7:07am UTC](https://forum.ionicframework.com/t/reload-view-after-login-pop/80221 "2017-02-20T07:07:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![keithmichelson](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@keithmichelson](https://forum.ionicframework.com/u/keithmichelson)\
**Post date:** [February 20, 2017, 7:07am UTC](https://forum.ionicframework.com/t/reload-view-after-login-pop/80221/1 "2017-02-20T07:07:51Z")

</div>

I have a default home page that checks for a login token, if not it pops in a login page. After login the page pops off and reveals the default page again but it needs to load again with the current user info.  
I am firing an event on login that the home page is listening for to reload the data but the view doesn’t change with the new data unless I click a tab and then back.

What would be the best way to do that? I’ve tried all the lifecycle hooks, do I just reload the default page again? If so, how would I do that?

Thanks for any help.

Keith

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [February 20, 2017, 7:17am UTC](https://forum.ionicframework.com/t/reload-view-after-login-pop/80221/2 "2017-02-20T07:17:36Z")

</div>

IMHO this should not be the home page’s problem, and if you architect it that way, your issue should go away. Some other gatekeeper (the app component is a potential choice) should decide whether to make its root page either the home page or the login page. See [here](https://forum.ionicframework.com/t/solved-ionic2-navcontroller-pop-with-params/58104/19) for details on how I handle this situation.

---

<div class="post-metadata">

**Author:** ![keithmichelson](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@keithmichelson](https://forum.ionicframework.com/u/keithmichelson)\
**Post date:** [February 20, 2017, 7:44am UTC](https://forum.ionicframework.com/t/reload-view-after-login-pop/80221/3 "2017-02-20T07:44:10Z")

</div>

Thanks for the advice. I will give that all I try.

---

<div class="post-metadata">

**Author:** ![keithmichelson](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@keithmichelson](https://forum.ionicframework.com/u/keithmichelson)\
**Post date:** [February 20, 2017, 6:44pm UTC](https://forum.ionicframework.com/t/reload-view-after-login-pop/80221/4 "2017-02-20T18:44:24Z")

</div>

@rapropos That all makes sense now, the only issue is Home is a tab page and login is a regular page I’m popping on the stack.

I can’t get this part of your code to direct correctly, am I missing something. I’m not sure how to navigate in app.component.

if (authed) {  
this.rootPage = AuthedPage;  
} else {  
this.rootPage = UnauthedPage;  
}

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [February 20, 2017, 7:24pm UTC](https://forum.ionicframework.com/t/reload-view-after-login-pop/80221/5 "2017-02-20T19:24:53Z")

</div>

Assuming your app.template.html has the typical:

```auto
<ion-nav [root]="rootPage">

```

, then simply assigning to the `rootPage` property should provide all the navigation needed.

---

<div class="post-metadata">

**Author:** ![keithmichelson](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@keithmichelson](https://forum.ionicframework.com/u/keithmichelson)\
**Post date:** [February 20, 2017, 8:00pm UTC](https://forum.ionicframework.com/t/reload-view-after-login-pop/80221/6 "2017-02-20T20:00:54Z")

</div>

Yeah it has that and then in the component it has rootPage = TabsPage;  
I did give it to navigate to the login page, but then I can’t see a way to start up the tabs and go back to the 1st default tab.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [February 20, 2017, 8:05pm UTC](https://forum.ionicframework.com/t/reload-view-after-login-pop/80221/7 "2017-02-20T20:05:26Z")

</div>

If you’re following the flow in that post exactly, when `setJwt` is called, that should happen automatically for you. If you’re picking up just bits of it, you need to call `next(true)` on whatever subject you’re subscribing to in the app component’s constructor.

---

<div class="post-metadata">

**Author:** ![keithmichelson](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@keithmichelson](https://forum.ionicframework.com/u/keithmichelson)\
**Post date:** [February 21, 2017, 2:58am UTC](https://forum.ionicframework.com/t/reload-view-after-login-pop/80221/9 "2017-02-21T02:58:53Z")

</div>

I’ve just about got your sink working, but I’m getting one error on this:

```
setJwt(jwt: string): Promise<void> {
this._jwt = jwt;
this._authNotifier.next(!!jwt);
// save it in storage, return resultant promise
}

```

A function whose declared type is neither ‘void’ nor ‘any’ must return a value.

I’m not sure what to return.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [February 21, 2017, 4:08am UTC](https://forum.ionicframework.com/t/reload-view-after-login-pop/80221/10 "2017-02-21T04:08:03Z")

</div>

> [@keithmichelson](#):
>
> I’m not sure what to return.

Something like this:

```auto
return this._storage.set("authorizationToken", jwt).then(() => {
  // do whatever stuff you need to do internally
});

```

If you don’t want to store the token in storage, feel free to simply return `Promise.resolve()`, or change the return type of the function to `void`. There are times when I want the caller to know that the token has successfully been saved in local storage, and potentially take other actions if it hasn’t / until it does. If that’s not a concern for you, feel free to ignore all of that and just return `void`.

---

<div class="post-metadata">

**Author:** ![keithmichelson](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@keithmichelson](https://forum.ionicframework.com/u/keithmichelson)\
**Post date:** [February 21, 2017, 4:47am UTC](https://forum.ionicframework.com/t/reload-view-after-login-pop/80221/11 "2017-02-21T04:47:29Z")

</div>

Okay, I finally got it all. That took me way too long, mainly because of my lack of knowledge with RX/JS and a couple other missing pieces I couldn’t figure out.

Thanks for all the help, and yes I did want to store it, just took me a sec.

Not sure if it makes a difference but I put it in the platform function in app.component.ts

```
constructor(platform: Platform, sink: SinkService) {
platform.ready().then(() => {
  // Okay, so the platform is ready and our plugins are available.
  // Here you can do any higher level native things you might need.
  sink.authenticationNotifier().subscribe((authed) => {
    if (authed) {
      this.rootPage = TabsPage;
    } else {
      this.rootPage = LoginPage;
    }
  });

  StatusBar.styleDefault();
  Splashscreen.hide();
});

```

}

In SinkService.js

```
setJwt(jwt: string): Promise<void> {
this._jwt = jwt;
this._authNotifier.next(!!jwt);
// save it in storage, return resultant promise
return this.storage.set('Token');

```

}

and I had to remove the pop() in the login, it was causing an error but worked without.

```
this.httpService.signIn(form.value).subscribe((response) => {
  let authtoken = response;
  this.sink.setJwt(authtoken).then(() => {
    //this.navCtrl.pop();
  });
});

```

and my logout button

```
doLogout() {
this.httpService.logOut()
  .subscribe(
    (res: any) => {
      this.storage.remove('Token');
      this.sink.setJwt(null);
    }
  );

```

}

And that works out really nice for my http.service.ts when making requests.

```
setupAuth() {
  let tokenFromSink = this.sink.getJwt();
  const headers = new Headers();
  headers.append('Content-Type', 'application/json');
  headers.append('Auth', tokenFromSink);
  return headers;
}
```
