I’m trying to enrich the data of a user with additional information. For this I have created a custom controller in which I get the user. Now I’ve noticed two weirdnesses:
When I started my project I was using Strapi v3 where I could get the user from ctx.state.user in my custom route, when the user had a JWT present. This, however didn’t seem to work in v4 which is why I made a workaround like this:
Which got me the user. First of all, is this the right way to do this? My guess is it’s not, but I was unable to find an alternative solution as the jwt.getToken() only returned the userId.
Secondly, and more importantly, when I’m querying for the user in the way described above, how does sanitization work in v4? v3 offered the sanitizeEntity() -function, which in v4 seems to have gone. Someone on stackoverflow suggested using sanitizeOutput(user, ctx) but I can’t seem to find this function anywhere in the strapi source, i.e. I can’t require it and when I just use it as described above, my server dies with a sanitizeOutput is not defined- exception.
Hi @JustJerem unfortunately not I did some digging into the source but my js knowledge is only average and I couldn’t figure out what is happening there. I’m surprised that no one else faces that issue, since my guess would be that this should be an issue that more users would face. Sorry I can’t help you out there. Maybe someone else will find a solution eventually.
You sir, are a lifesaver. Thanks so much for this, I’ve been trying quite some time to find a solution to this, but I’m not exactly what you would consider a good coder.
I wish you a nice weekend and great success with whatever it is you’re working on.