Ok I have tested it and it did not work in deed. Problem is timing between loginRequired and response from first command where we fetched the session. So session required for login was set after login which fails for using wrong session id in authentification. See this socket communication:
{"action":"listPrinter","data":{},"printer":"","callback_id":1}63
12:19:06.111
{"callback_id":-1,"data":[{"data":{"session":"dHq2Mpcle!W!2iIGFO5!neg!e8TO2#u6"},"event":"loginRequired","printer":""}],"eventList":true}137
12:19:06.213
{"action":"login","data":{"login":"repetier","password":"5668967689678689"},"printer":"","callback_id":2}121
12:19:06.214
{"callback_id":1,"data":{"permissionDenied":true},"session":"dHq2Mpcle!W!2iIGFO5!neg!e8TO2#u6"}95
12:19:06.216
Solution is to use the session already provided in the loginRequired event so we definitively use the correct one.
I have updated the demo accordingly.