SessionStorage data not stored in AngularJS application with ngStorage

All,

I'm just trying to save a custom object in sessionStorage in an AngularJS application. If I go through this in a Chrome or FF debugger, sessionStorage will never be installed. Here is my angular utility code:

// Authentication/authorization Module
stonewall.authModule = angular.module("authModule", [
    // Module dependencies
    "ngStorage"
    ]);

// Authentication/authorization service tracks the current user
stonewall.authModule.service('authService', function ($localStorage, $sessionStorage) {

    // Initialize current user
    var currentUser = {};
    restoreSession();

    // Declare storage type-this may change if user selects
    // "Keep me signed in"
    var storageType = {};

    // Return the current user object
    this.getCurrentUser = function () {
        return currentUser;
    };
    // Returns whether there is a currently authorized user
    this.userAuth = function() {
        return currentUser.sid != "";
    };
    // Logout function, initializes the user object
    this.logout = function() {
        currentUser = {
            sid: "",
            status: 0,
            pswLastSet: 0,
            id: "",
            sigUID: "",
            sig: ""
        };
        //persistSession();
    };
    // Login
    this.login = function(user, subj) {
        if (user == null) return;
        currentUser = {
            sid: user.Principal.SId,
            status: user.Principal.ControlStatus,
            pswLastSet: new Date(user.Principal.PasswordLastSet),
            id: user.Identity.Id.DN,
            sigUID: user.Identity.Certificates[0].UID,
            sig: stonewall.hash(user.Principal.SId + subj.pswd),
        };
        persistSession();
    };
    // Persist to session storage
    function persistSession() {
        $sessionStorage.currentUser = currentUser;
    };
    // Restore session
    function restoreSession() {
        currentUser = $sessionStorage.currentUser;
        if (currentUser == null) {
            // Initialize to empty user
            currentUser = {
                sid: "",
                status: 0,
                pswLastSet: 0,
                id: "",
                sigUID: "",
                sig: ""
            };
        }
    };
});

And here is a screencast that shows my FF debugging session. You can see that after persistSession is called, $ sessionStorage has my user.

Debugger

But if I go to the DOM inspector, sessionStorage has no elements in it ...

Dom

Any help, as always, is appreciated.

+4
source share
1 answer

, angular sessionStorage ? $window angular, , - ? , , , , $window.sessionStorage: http://codepen.io/chrisenytc/pen/gyGcx

+4

Source: https://habr.com/ru/post/1543593/


All Articles