Skip to content

local storage is getting cleared when closing the window. How to stop it? #5708

Closed

Description

@bansalvks
  • Electron version: 1.1.0
  • Operating system: OSX 10.5

I am storing some information e.g. user name, email so on, in localStorage to access next time user will start my application but its gone if the user closes the window.

I am using localStorage from my angular app. Code is given below


myAppServices.service('localStorageService', [function () {

    /// userdetails
    this.setUserDetailsGoogle = function (userDetailsGoogle) {

        if (userDetailsGoogle === undefined) {
            return false
        }

        localStorage.userDetailsGoogle = JSON.stringify(userDetailsGoogle);
        return true;
    };

    this.getUserDetailsGoogle = function () {
        if (localStorage.userDetailsGoogle === undefined) {
            return null;
        }

        return JSON.parse(localStorage.userDetailsGoogle);
    };


    /// googleauth details
    this.setOauthDetailsGoogle = function (oauthDetailsGoogle) {

        if (oauthDetailsGoogle === undefined) {
            return false;
        }

        localStorage.oauthDetailsGoogle = JSON.stringify(oauthDetailsGoogle);
        return true;
    }

    this.getOauthDetailsGoogle = function () {
        if (localStorage.oauthDetailsGoogle === undefined) {
            return null;
        }

        return JSON.parse(localStorage.oauthDetailsGoogle);
    };

    return this;
}]);

What should I do? Please help..

Activity

  1. jlord commented on May 26, 2016

    @jlord
    Contributor

    As mentioned #1731 (comment), localStorage's default behavior is not to persist after certain types of closes/crashes.

    This is likely not an issue with Electron, closing out.

  2. ramtinsoltani commented on May 24, 2019

    @ramtinsoltani

    @jlord I'm on Ubuntu 18.04 LTS and when I close the application normally by clicking the X button on the window and then relaunching the app, the local storage is gone. I've also built the app into a .deb and installed it, the local storage problem still exists.

  3. johannesjo commented on Sep 14, 2019

    @johannesjo

    @ramtinsoltani exactly that. I don't understand why the storage gets cleared completely. I would understand if the current changes would be thrown away. But clearing it completely doesn't happen in a normal browser.

  4. johannesjo commented on Sep 14, 2019

    @johannesjo

    What actually helps is when I do the following:

    process.on('exit', () => {
      app.quit();
    });
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions