Strapi Version: 3.5.x
Operating System: Windows 10
Node Version: 14.x
NPM Version: 6.x
Yarn Version: 1.22.5
Hey guys, this may be a very stupid question, but I just want to retrieve the username when the user navigates back to their dashboard but I can’t find any documentation for an API endpoint for anything like that related to the user. Something like ‘auth/local’? Any help is greatly appreciated.
Hi @conorjohn! Thanks for the question.
There isn’t any documentation that sticks out to help a user pull information about the currently authenticated user but here’s the thing. Strapi exposes ways to interact with an API by way of controllers. These controllers are functions (or small pieces of functionality, e.g ‘find’ would find a certain item) that you can interact with from, say, the API to have the data you need. A trick I recommend to them is, go to the Role Permissions (
Settings > Users & Permissions Plugin > Roles > Authenticated > Users & Permissions ) and see the list of all controllers available for use. Like in the screenshot attached. In their case, they should use the endpoint
/users/me. Why ‘users’? This is because the “me” controller is under the “User” sub-category. It is pluralized because for logical reasons, there are many “User” objects i.e “users”. The other sub-categories (Auth and Userpermissions) are not pluralized in the API URL. So they would do something like:
http://localhost:1337/users/me to get information about the currently authenticated user.