sessionStorage data not persist in AngularJS app with ngStorage


I'm simply trying to store a user object in sessionStorage in an AngularJS app. If I step through this in either the Chrome or FF debugger, the sessionStorage never gets set. Here is my angular service code:

// Authentication/authorization Module
stonewall.authModule = angular.module("authModule", [
    // Module dependencies

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

    // Initialize current user
    var currentUser = {};

    // 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: ""
    // 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),
    // 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 screencap that shows my FF debugging session. You can see that after persistSession is called that $sessionStorage has my user.

But, if I switch over to the DOM inspector, sessionStorage has no items in it...

Any help is, as always, appreciated.


Are you sure you are using angular's sessionStorage in the right way? Session storage is a property of the $window object in angular, so I don't know if you have made your own service wrapper or something like that? Anyway, here is a codepen that shows another approach that I use myself, using $window.sessionStorage instead:

Need Your Help

How to get a Date object from String

java date datetime simpledateformat

DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy' 'HH:mm:ss");

Recursively call a method to build Binary Search Tree

java recursion binary-tree

I'm trying to build a binary search tree given an ArrayList of sorted values. In trying to create the most efficient tree possible I take the middle value, and add it to the tree. Then recursively ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.