You could try something like this:
<script type="text/discourse-plugin" version="0.8.27">
let currentUser = api.getCurrentUser();
if (currentUser) {
api.container.lookup('store:main').find('user', currentUser.username).then((user) => {
console.log('user', user.user_fields);
});
}
</script>
See Using the PluginAPI in Site Customizations for details about the "text/discourse-plugin"
script type.