# How to keep the user logged even if he closes the app

**URL:** <https://forum.ionicframework.com/t/how-to-keep-the-user-logged-even-if-he-closes-the-app/50100>\
**Category:** ionic-v1\
**Created:** [April 22, 2016, 9:46am UTC](https://forum.ionicframework.com/t/how-to-keep-the-user-logged-even-if-he-closes-the-app/50100 "2016-04-22T09:46:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Doun1a](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@Doun1a](https://forum.ionicframework.com/u/Doun1a)\
**Post date:** [April 22, 2016, 9:46am UTC](https://forum.ionicframework.com/t/how-to-keep-the-user-logged-even-if-he-closes-the-app/50100/1 "2016-04-22T09:46:57Z")

</div>

Hi. I’ve been searching for this but ican’t find a good answer. I’m a beginner with Ionic and I want the user to stay logged in even if he closes the app. How can i make it work ? do I have to use localstorage ? but how ? Thanks

---

<div class="post-metadata">

**Author:** ![Babinc](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/babinc/32/92168_2.png) [@Babinc](https://forum.ionicframework.com/u/Babinc)\
**Post date:** [April 24, 2016, 3:03am UTC](https://forum.ionicframework.com/t/how-to-keep-the-user-logged-even-if-he-closes-the-app/50100/2 "2016-04-24T03:03:01Z")

</div>

Here some sample code of something you can do. You will need to implement your own logic to determine if the user is already logged in. But you could possibly save user Information using window.localStorage.

```
$ionicPlatform.ready(function() {
  if (AuthService.isLoggedIn()) {
    $state.go('tab.home');
  }
  else {
    $state.go('auth.welcome');
  }
...(rest of your ready code)
});
```

---

<div class="post-metadata">

**Author:** ![bengtler](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bengtler/32/98565_2.png) [@bengtler](https://forum.ionicframework.com/u/bengtler)\
**Post date:** [April 24, 2016, 10:32am UTC](https://forum.ionicframework.com/t/how-to-keep-the-user-logged-even-if-he-closes-the-app/50100/3 "2016-04-24T10:32:46Z")

</div>

or if you want to be safe, that the localstorage is not cleared after os updates or something use persistent storage (a json-file) or sqlite plugin.

---

<div class="post-metadata">

**Author:** ![Doun1a](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@Doun1a](https://forum.ionicframework.com/u/Doun1a)\
**Post date:** [April 25, 2016, 9:56am UTC](https://forum.ionicframework.com/t/how-to-keep-the-user-logged-even-if-he-closes-the-app/50100/4 "2016-04-25T09:56:23Z")

</div>

Thank you so much for your help

---

<div class="post-metadata">

**Author:** ![Doun1a](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@Doun1a](https://forum.ionicframework.com/u/Doun1a)\
**Post date:** [April 25, 2016, 10:13am UTC](https://forum.ionicframework.com/t/how-to-keep-the-user-logged-even-if-he-closes-the-app/50100/5 "2016-04-25T10:13:05Z")

</div>

Thank you so much for your help
