Hello. I’m trying to get frappe.session.user_fullname from a custom js in hooks.py
I am using the user “Administrator” and this code to verify that it is getting the data correctly:
document.addEventListener("DOMContentLoaded", function () {
var isAdmin = frappe.session.user_fullname === 'Administrator';
console.log(isAdmin)
});
Always returns false. Instead, using only frappe.session.user_fullname from chrome console it returns result correctly
Any ideas? My goal is to hide some content taking the user (or the role) into consideration, but for some reason I cannot access the data from custom js.
I put frappe.session.user_fullname because it was what I was checking at the time (I had already tried it before, and multiple more variants xD), with frappe.session.user the result is the same:
document.addEventListener("DOMContentLoaded", function () {
console.log("User:", frappe.session.user);
});
Output = “User: undefined”
With frappe.boot.user.name (I didn’t know about it), it seems to work:
document.addEventListener("DOMContentLoaded", function () {
console.log('22');
console.log("User:", frappe.boot.user.name);
});