Visualize.js authentication error after second login

♀尐吖头ヾ 提交于 2020-01-02 08:11:41

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/30519192/visualize-js-authentication-error-after-second-login

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!