If you are developing components for discourse… I think the easiest way is to use discourse’s api. If you are developing a client, I think the user name should have been known long ago?
For the former, here is an example;
require("discourse/lib/plugin-api").withPluginApi("1.0.0", (api)=>{console.log(api.currentUser())});