Hi, for several reason I need a simple button to logout embedded within the dashboard.
Generally it’s not a big problem and I solved it using the html panel plugin
HTML plugin for Grafana | Grafana Labs and cleaning the related grafana’s cookies
The problem is that my code works fine if I reach grafana like www.mydomain.com. But if I reach it simply with mydomain.com (without www), I apparently logout correctly but, next time I open the page I get directly login as I never logout. Pratically it was a fake logout.
This is the code in the html panel:
var logout_btn=htmlnode.getElementById('logout_btn');
logout_btn.addEventListener('click',logout);
function logout(){
deleteCookie("grafana_session");
window.location.replace("https://www.mydomain/grafana/logout/");
}
function writeCookie(nameCookie,valueCookie,timeCookie){
var ending_time = new Date();
var now_time = new Date();
ending_time.setTime(now_time.getTime() + (parseInt(timeCookie) * 60000));
document.cookie = nameCookie + '=' + escape(valueCookie) + '; expires=' + ending_time.toGMTString() + '; path=/';
}
function deleteCookie(nameCookie){
writeCookie(nameCookie,'',-1);
}
I run Grafana behind nginix. Thanks a lot