# Ways on how to integrate "Remember me" or "Keep me Signed in"

**URL:** <https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727>\
**Category:** ionic-v1\
**Created:** [July 5, 2015, 11:59pm UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727 "2015-07-05T23:59:17Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![bonlemuel](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bonlemuel/32/13545_2.png) [@bonlemuel](https://forum.ionicframework.com/u/bonlemuel)\
**Post date:** [July 5, 2015, 11:59pm UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/1 "2015-07-05T23:59:17Z")

</div>

Hi Ionic Developers,

I want the user of my application to be always logged in even when offline, just like Facebook. How can I achieve this?

I found ways on the internet already, but maybe there’s some more ideas out there? 😄

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![m2m](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/m2m/32/77446_2.png) [@m2m](https://forum.ionicframework.com/u/m2m)\
**Post date:** [July 6, 2015, 12:34am UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/2 "2015-07-06T00:34:38Z")

</div>

i use `satellizer` and they implemented ready functionality `isAuthenticated()` for this. You can check the state saved in the local Storage to check if user previously logged in.

---

<div class="post-metadata">

**Author:** ![nnnnnorthhhhh](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/nnnnnorthhhhh/32/98566_2.png) [@nnnnnorthhhhh](https://forum.ionicframework.com/u/nnnnnorthhhhh)\
**Post date:** [July 6, 2015, 5:40am UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/3 "2015-07-06T05:40:14Z")

</div>

My app uses basic token authentication, so basically once a user is logged in, unless they log out somewhere else they are still authenticated from that device.

I turn my auto hide splash screen setting to off in the config.xml and then when I load the app the login screen (hidden by the splash) checks to see if they are still authenticated by making a call using that token as their authentication.

If the user fails auth for example if their session timed out, or they logged in somewhere else maybe (If you track web/mobile tokens separately they could be logged in on both places) then it hides the splash screen and lets them log in.

If they pass authentication i hide the splash screen about 500ms after the state has changed to the home screen.

This makes for a really smooth and nice auto login set up. Then in my settings I’ve got a toggle they can hit if they prefer to log in each time.

---

<div class="post-metadata">

**Author:** ![bonlemuel](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bonlemuel/32/13545_2.png) [@bonlemuel](https://forum.ionicframework.com/u/bonlemuel)\
**Post date:** [July 6, 2015, 6:37am UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/4 "2015-07-06T06:37:53Z")

</div>

Hi @m2m,

Will this work on Mobile?

Thanks.

---

<div class="post-metadata">

**Author:** ![m2m](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/m2m/32/77446_2.png) [@m2m](https://forum.ionicframework.com/u/m2m)\
**Post date:** [July 6, 2015, 6:10pm UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/5 "2015-07-06T18:10:27Z")

</div>

Yes they also posted an example for ionic.

---

<div class="post-metadata">

**Author:** ![bonlemuel](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bonlemuel/32/13545_2.png) [@bonlemuel](https://forum.ionicframework.com/u/bonlemuel)\
**Post date:** [July 6, 2015, 10:20pm UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/6 "2015-07-06T22:20:07Z")

</div>

I am not sure why this happen. I successfully integrated the `satellizer` on my project. When running it on emulator or by “ionic serve”, the app loads. But when I try running it on an actual device (iPhone), it did not load. What do you think the problem is? Thanks!

---

<div class="post-metadata">

**Author:** ![m2m](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/m2m/32/77446_2.png) [@m2m](https://forum.ionicframework.com/u/m2m)\
**Post date:** [July 6, 2015, 10:33pm UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/7 "2015-07-06T22:33:38Z")

</div>

can you post a log to your app.

---

<div class="post-metadata">

**Author:** ![bonlemuel](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bonlemuel/32/13545_2.png) [@bonlemuel](https://forum.ionicframework.com/u/bonlemuel)\
**Post date:** [July 7, 2015, 5:12am UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/8 "2015-07-07T05:12:27Z")

</div>

Here’s the log:

```
2015-07-07 13:09:57.583 eBayanihan Mobile[4145:1196399] DiskCookieStorage changing policy from 2 to 0, cookie file: file:///private/var/mobile/Containers/Data/Application/A54E05FC-308C-4BB1-9D4B-D86F75B17D60/Library/Cookies/Cookies.binarycookies
2015-07-07 13:09:57.896 eBayanihan Mobile[4145:1196399] Apache Cordova native platform version 3.8.0 is starting.
2015-07-07 13:09:57.899 eBayanihan Mobile[4145:1196399] Multi-tasking -> Device: YES, App: YES
2015-07-07 13:09:57.909 eBayanihan Mobile[4145:1196399] Unlimited access to network resources
2015-07-07 13:09:58.108 eBayanihan Mobile[4145:1196399] [CDVTimer][keyboard] 0.331044ms
2015-07-07 13:09:58.109 eBayanihan Mobile[4145:1196399] [CDVTimer][TotalPluginStartup] 0.934005ms
2015-07-07 13:09:58.583 eBayanihan Mobile[4145:1196399] Resetting plugins due to page load.
2015-07-07 13:09:58.795 eBayanihan Mobile[4145:1196399] Finished load of: file:///private/var/mobile/Containers/Bundle/Application/FCC663EE-64B6-48C1-984D-28BF1C136FE9/eBayanihan%20Mobile.app/www/index.html
2015-07-07 13:09:58.801 eBayanihan Mobile[4145:1196399] Resetting plugins due to page load.
2015-07-07 13:10:05.022 eBayanihan Mobile[4145:1196399] Finished load of: file:///private/var/mobile/Containers/Bundle/Application/FCC663EE-64B6-48C1-984D-28BF1C136FE9/eBayanihan%20Mobile.app/www/main.html
```

---

<div class="post-metadata">

**Author:** ![aaronksaunders](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/aaronksaunders/32/13729_2.png) [@aaronksaunders](https://forum.ionicframework.com/u/aaronksaunders)\
**Post date:** [July 7, 2015, 5:29pm UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/9 "2015-07-07T17:29:46Z")

</div>

looks interesting… this is is a local library? no need for additional server code other than the

---

<div class="post-metadata">

**Author:** ![bonlemuel](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bonlemuel/32/13545_2.png) [@bonlemuel](https://forum.ionicframework.com/u/bonlemuel)\
**Post date:** [July 8, 2015, 1:22am UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/10 "2015-07-08T01:22:03Z")

</div>

other than the… ? hehe 🙂

---

<div class="post-metadata">

**Author:** ![santinowu](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/santinowu/32/7815_2.png) [@santinowu](https://forum.ionicframework.com/u/santinowu)\
**Post date:** [July 9, 2015, 3:29pm UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/11 "2015-07-09T15:29:10Z")

</div>

Hi,

My solution is persist user certification in the `localstorage` like what @m2m do.

To define an `User` object to store certification and an `UserService` to handle `User` object, here is an example(do not use this in production):

```js
var User = function (username, token, authenticated) {
  this.username = username;
  this.token = token;
  this.authenticated = false;
};

// Notice: I use `angular-local-storage` here
angular.module('YOUR_APP', ['LocalStorageModule', ...])
  .service('UserService', function ($http, localStorageService) {
    var user = new User(null, null, false);

    var userService = {
      init: function () {
        // Retrieve information from local storage
        var credential = localStorageService.get(CACHE_KEY, credential);

        // Reload user
        this.reload().then(function (user) {
          user.username = user.username;
          user.token = credential;
          user.isAuthentiated = true;
        });
      },
      persist: function () {
        localStorageService.set(CACHE_KEY, credential);
      },
      reload: function () {
        // To authenticate user from server and fetch user data,
        // do not forget to handle error from server.
        // @return {Promise}
        return $http.post(YOUR_SERVER_URL_FOR_AUTHENTICATE_USER);
      },
      clear: function () {
        user.username = null;
        user.token = null;
        user.isAuthentiated = false;
      },
      isAuthenticated: function () {
        return user.isAuthenticated;
      },
      // ...
    };
    
    return userService;
  });

```

Create a `UserService` depending on your requirement(like auth, store credential, a http interceptor etc) to maintain `User` object will make things easy.

* * *

> [@bonlemuel](#):
>
> Will this work on Mobile?

Check this [website (http://caniuse.com/#search=localstorage)](http://caniuse.com/#search=localstorage), 😄

---

<div class="post-metadata">

**Author:** ![darshanp](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@darshanp](https://forum.ionicframework.com/u/darshanp)\
**Post date:** [September 14, 2015, 3:13pm UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/12 "2015-09-14T15:13:37Z")

</div>

Do you have any code that you could share of this being done?

In particular, code for hiding the splash screen after the home view has been loaded:

> If they pass authentication i hide the splash screen about 500ms after the state has changed to the home screen.

When I’m doing it, the login screen is briefly visible before the home screen loads.

---

<div class="post-metadata">

**Author:** ![chaitalidebp](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/chaitalidebp/32/12823_2.png) [@chaitalidebp](https://forum.ionicframework.com/u/chaitalidebp)\
**Post date:** [February 2, 2016, 9:25am UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/13 "2016-02-02T09:25:28Z")

</div>

Hi North,  
I am trying to do similar stuff as a remember me feature for an ionic enterprise app.I am using Session cookies/Jsession Id for session management.  
But once the app is killed the cookie is [destroyed.So](http://destroyed.So) I was trying to intercept the session cookie  
after login but I am unable to do that mobile browser.

Need help as its an urgent requirement.

Regards and Thanks  
Chaitali

---

<div class="post-metadata">

**Author:** ![bonlemuel](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bonlemuel/32/13545_2.png) [@bonlemuel](https://forum.ionicframework.com/u/bonlemuel)\
**Post date:** [February 2, 2016, 10:23am UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/14 "2016-02-02T10:23:49Z")

</div>

Hey, Have you tried saving a “value” on a local storage? Coz’ as far as I know it won’t get destroyed even if you killed the App. You can save the “cookie” on a Local Storage and create a function that will determine if such key exist. From there you can determine the state of the App.

---

<div class="post-metadata">

**Author:** ![chaitalidebp](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/chaitalidebp/32/12823_2.png) [@chaitalidebp](https://forum.ionicframework.com/u/chaitalidebp)\
**Post date:** [February 2, 2016, 12:59pm UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/15 "2016-02-02T12:59:14Z")

</div>

Thanks …I am trying to do the same thing but unable to catch the cookie from device browser,  
though it works fine for desktop browser when I am running Ionic serve…

Regards  
Chaitali

---

<div class="post-metadata">

**Author:** ![bonlemuel](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bonlemuel/32/13545_2.png) [@bonlemuel](https://forum.ionicframework.com/u/bonlemuel)\
**Post date:** [February 2, 2016, 1:00pm UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/16 "2016-02-02T13:00:38Z")

</div>

Have you tried using this one? [http://learn.ionicframework.com/formulas/localstorage/](http://learn.ionicframework.com/formulas/localstorage/)

---

<div class="post-metadata">

**Author:** ![nnnnnorthhhhh](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/nnnnnorthhhhh/32/98566_2.png) [@nnnnnorthhhhh](https://forum.ionicframework.com/u/nnnnnorthhhhh)\
**Post date:** [February 2, 2016, 4:49pm UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/17 "2016-02-02T16:49:36Z")

</div>

I don’t work with cookies very often, what you’re trying to do is what I would recommend. Enterprise systems get really touchy sometimes. Have you tried looking for a cookie library with cordova? Maybe there is an API that exposes those

---

<div class="post-metadata">

**Author:** ![chaitalidebp](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/chaitalidebp/32/12823_2.png) [@chaitalidebp](https://forum.ionicframework.com/u/chaitalidebp)\
**Post date:** [February 3, 2016, 9:23am UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/18 "2016-02-03T09:23:26Z")

</div>

Hi North,  
If not cookies what is the best approach to do this for Ionic apps…  
Regards  
Chaitali

---

<div class="post-metadata">

**Author:** ![nnnnnorthhhhh](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/nnnnnorthhhhh/32/98566_2.png) [@nnnnnorthhhhh](https://forum.ionicframework.com/u/nnnnnorthhhhh)\
**Post date:** [February 3, 2016, 5:11pm UTC](https://forum.ionicframework.com/t/ways-on-how-to-integrate-remember-me-or-keep-me-signed-in/27727/19 "2016-02-03T17:11:39Z")

</div>

Local Storage is the best option for something like this. Local storage isn’t permanent, but it is a lot easier to work with in Javascript. ngStorage is an angularjs module for managing the local storage, it’s a great option.
