# Stay logged in with data in local storage

**URL:** <https://forum.ionicframework.com/t/stay-logged-in-with-data-in-local-storage/126244>\
**Category:** ionic-v3\
**Created:** [March 28, 2018, 7:56pm UTC](https://forum.ionicframework.com/t/stay-logged-in-with-data-in-local-storage/126244 "2018-03-28T19:56:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lado](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@lado](https://forum.ionicframework.com/u/lado)\
**Post date:** [March 28, 2018, 7:56pm UTC](https://forum.ionicframework.com/t/stay-logged-in-with-data-in-local-storage/126244/1 "2018-03-28T19:56:22Z")

</div>

Hello,

I’m trying to figure out how to stay logged in.

Persistent data in local storage must be useful in this case, I’m not sure if it is correct, to use `import { Storage } from '@ionic/storage';`

Advice would be useful

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [March 28, 2018, 7:59pm UTC](https://forum.ionicframework.com/t/stay-logged-in-with-data-in-local-storage/126244/2 "2018-03-28T19:59:01Z")

</div>

Logged in to what exactly?

---

<div class="post-metadata">

**Author:** ![lado](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@lado](https://forum.ionicframework.com/u/lado)\
**Post date:** [March 28, 2018, 8:23pm UTC](https://forum.ionicframework.com/t/stay-logged-in-with-data-in-local-storage/126244/3 "2018-03-28T20:23:51Z")

</div>

Hello, Sujan12

Thanks for answer

To make user able to stay logged in his account settings data, which is stored on MySql database, but not attached to the particular user with logout from the application or after turning off phone

I’m new with Ionic2 and Type Script, maybe I’m not on the right direction, as I understand it, I have to create some key to attach particular user with his account, but if it is wrong, would be helpful, to know a proper method or more correct way of solution

---

<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:** [March 28, 2018, 8:28pm UTC](https://forum.ionicframework.com/t/stay-logged-in-with-data-in-local-storage/126244/4 "2018-03-28T20:28:12Z")

</div>

> [@lado](#):
>
> I have to create some key to attach particular user with his account

This is an extremely complex problem with substantial security implications. I would strongly urge you to adopt tested technology like [JSON Web Tokens](https://jwt.io/) here instead of trying to develop your own protocol. You can persist the JWT in Storage on the device and reload it on app launch. This should have the effect of “keeping the user logged in” for as long as the token itself is valid, which you can control depending on your needs.

---

<div class="post-metadata">

**Author:** ![lado](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@lado](https://forum.ionicframework.com/u/lado)\
**Post date:** [March 29, 2018, 12:19am UTC](https://forum.ionicframework.com/t/stay-logged-in-with-data-in-local-storage/126244/5 "2018-03-29T00:19:46Z")

</div>

Hello, rapropos

Thank you for your answer, very useful

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:42pm UTC](https://forum.ionicframework.com/t/stay-logged-in-with-data-in-local-storage/126244/6 "2021-07-19T21:42:36Z")

</div>

Closed on July 19, 2021, 9:42pm UTC


