diff --git a/assets/src/bundles/webapp/webapp-utils.js b/assets/src/bundles/webapp/webapp-utils.js --- a/assets/src/bundles/webapp/webapp-utils.js +++ b/assets/src/bundles/webapp/webapp-utils.js @@ -395,3 +395,7 @@ swhidInputElt.setCustomValidity(customValidity); $(swhidInputElt).siblings('.invalid-feedback').text(customValidity); } + +export function isUserLoggedIn() { + return JSON.parse($('#swh_user_logged_in').text()); +} diff --git a/cypress/integration/admin.spec.js b/cypress/integration/admin.spec.js --- a/cypress/integration/admin.spec.js +++ b/cypress/integration/admin.spec.js @@ -59,6 +59,22 @@ logout(); }); + it('should get info about a user logged in from javascript', function() { + cy.window().then(win => { + expect(win.swh.webapp.isUserLoggedIn()).to.be.false; + }); + cy.adminLogin(); + cy.visit(url); + cy.window().then(win => { + expect(win.swh.webapp.isUserLoggedIn()).to.be.true; + }); + logout(); + cy.visit(url); + cy.window().then(win => { + expect(win.swh.webapp.isUserLoggedIn()).to.be.false; + }); + }); + it('should prevent unauthorized access after logout', function() { cy.visit(this.Urls.admin_origin_save()) .location('pathname') diff --git a/swh/web/templates/layout.html b/swh/web/templates/layout.html --- a/swh/web/templates/layout.html +++ b/swh/web/templates/layout.html @@ -56,6 +56,8 @@ swh.webapp.setSwhObjectIcons({{ swh_object_icons|jsonify }}); + {{ request.user.is_authenticated|json_script:"swh_user_logged_in" }} + {% block header %}{% endblock %}