Logout button within panel

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');
function 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){

I run Grafana behind nginix. Thanks a lot

For who face the same problem, I solved it choising www.mydomain.com as the main one in nginx and redirecting mydomain.com to it