How to use the store2.session function in store2

To help you get started, we’ve selected a few store2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mallim / sbangular / src / main / resources / js / security / TestAuthService.js View on Github external
it('should be able to login successfully', inject(['AuthService','$httpBackend','$rootScope', function( AuthService, $httpBackend, $rootScope ) {

    $httpBackend.whenPOST('user/authenticate', null).respond( 200, 'Done' );
    $httpBackend.whenGET('user/authenticated/retrieve').respond( {"password":null,"username":"user","authorities":[{"authority":"ROLE_USER"}],"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"enabled":true});

    var spy = sinon.spy($rootScope, "$emit");
    var spy2 = sinon.spy($rootScope, '$broadcast');
    AuthService.login( $rootScope, "user", "user" );
    expect(spy).to.have.been.calledWith("event:loginRequest");

    $rootScope.$apply();
    $httpBackend.flush();

    // Verify login function
    expect(spy2).to.have.been.calledWith("event:loginConfirmed");
    expect(store.session.get("userInfo")).not.to.be.null;
    expect($rootScope.user).not.to.be.null;
    expect($rootScope.userInfo).not.to.be.null;

    // Verify isLoggedIn function
    expect(AuthService.isLoggedIn()).to.be.true;

    // Verify logout function
    AuthService.logout( $rootScope ).then(function() {
      expect(store.session.get("userInfo")).to.be.null;
      expect(spy).to.have.been.calledWith("event:logoutRequest");
      expect($rootScope.user).to.be.null;
      expect($rootScope.userInfo).to.be.null;
    });

  }]));
github mallim / sbangular / src / main / resources / js / security / AuthService.js View on Github external
.then(function(results) {
            // console.log("results[1] ", results[ 1 ] );
            if( results[ 1 ] )
            {
              $rootScope.user = results[ 1 ].data;
              var userInfo = {
                authorities: results[ 1 ].data.authorities,
                userName: results[ 1 ].data.username
              };
              store.session.set( "userInfo", angular.toJson( userInfo ) );
              $rootScope.userInfo = userInfo;
              // console.log("Got the user to be ", user );
              $rootScope.$broadcast('event:loginConfirmed');
              delete $rootScope.error;
            }

            deferred.resolve(results[1].data);
        },
        function(error) {
github mallim / sbangular / src / main / resources / js / security / TestAuthService.js View on Github external
AuthService.logout( $rootScope ).then(function() {
      expect(store.session.get("userInfo")).to.be.null;
      expect(spy).to.have.been.calledWith("event:logoutRequest");
      expect($rootScope.user).to.be.null;
      expect($rootScope.userInfo).to.be.null;
    });
github explooosion / browndust-share / src / utils / Session.js View on Github external
export const set = (key = '', value = null) => {
  if (!key && !value) return;
  store.session(key, value);
}
github mallim / sbangular / src / main / resources / js / security / AuthService.js View on Github external
function AuthService(){
      if (store.session.has("userInfo")) {
        $rootScope.userInfo = angular.toJson(store.session.get("userInfo"));
      }
    }
github explooosion / browndust-share / src / utils / Session.js View on Github external
export const get = (key = '') => store.session(key);

store2

Better localStorage

MIT
Latest version published 2 months ago

Package Health Score

85 / 100
Full package analysis