3

I have a website—utilizing Visualize.js—that has a simple login/logout feature. Everytime I login I call the authenicateUser() function and logout destroySession(). When I try login and then logout and then login again, when I try to render my existing reports I get this thrown error:

HTTP Status 401 - Full authentication is required to access this resource

The functions authenicateUser() and destroySession() are shown below:

function authenticateUser () {
    var myConfig = {
        auth : {
            name     : "superuser",
            password : "superuser"
        }
    };
    visualize.config( myConfig );
}

function destroySession() {
    visualize( function ( v ) {
        // Logout form JRS and finish the session.
        v.logout().done( function () {
        } );
    } )
}

I would like to point out that when I first login my account this error is not thrown and renders the reports perfectly.

Why is this happening after logout and then login again?

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Monece Solis
  • 683
  • 2
  • 6
  • 23

2 Answers2

5

This seemed to have worked for me. So I called visualize.config( config ) first so that I can store common configuration, to share them between visualize calls and then called the login method so that I can perform authentification with provided auth object. My reference: http://community.jaspersoft.com/wiki/visualizejs-api-notes-and-samples-v56

        visualize.config( config );
        visualize( function ( v ) {
            v.login( config );
        } );

This solution was not in their documentation though, but I put them piece by piece to finally solve the problem.

Monece Solis
  • 683
  • 2
  • 6
  • 23
1

The documentation contained solution to this problem although it is not very explicit. See sample code and sample link from documentation link

visualize.config({
  auth: {
      name: "superuser",
      password: "superuser"
  }
});

Share common config between 'visualize' calls

Just a note: Actually when you login you need to logout at some appropriate event. This depends on your application requirement e.g. if you are embedding reports within an existing web application, it seems more appropriate to link it existing application login/lougut

M. Atif Riaz
  • 492
  • 1
  • 9
  • 22
  • It is not consistent to link to existing application login/logout, since that does not need to be flow to lose session. I used local storage to keep info about currently logged in user. Once user is changed, I see that through local storage and then do logout first, following with log in. Also, this solution requires additional check if user opens several tabs with visualize.js authentication code in same time. It could happen that one tab fire login and in meantime other tab fire logout. – Minja Apr 20 '16 at 21:08