As a headless developer I can access the current user's name, username, etc. easily
Originally:
https://github.com/apostrophecms/apostrophe-headless/issues/61
(Back in the A2 era, but still a good idea)
Right now a pure headless Apostrophe developer can't display the current user's name, which is silly and lacks parity with what Nunjucks developers can easily do.
Of course they can implement their own apiRoute for it at project level but it is good for headless developers to have access to things with roughly the same level of effort as those using ordinary full page Apostrophe rendering.
The goal is to implement the following API via the apiRoutes feature in Apostrophe's core login module:
GET /api/v1/@apostrophecms/login/whoami
Which would return the following information about the user who made the request (req.user):
{
_id,
username,
title,
email
}
The @apostrophecms/login module would be given new options, minimumWhoamiFields and whoamiFields. minimumWhoamiFields would default to [ '_id', 'username', 'title', 'email' ] and whoamiFields would default to []. The final list would be the concatenation of the two.
This is for convenience: developers can add fields without restating the list or accidentally breaking code that reasonably relies on this API's defaults unless they really want to go there.
If req.user does not exist a 404 should be generated (throw self.apos.error('notfound'))
Since we don't have a customer requirement for this at this time, I've tagged it for a potential open source community contribution. Due to the clear technical description above, I have also tagged it as a good first issue for anyone willing to spend time with the Apostrophe documentation re: apiRoutes.
[Internal note: see PRO-6828]
hi can i work on this issue is it still open to work on ?
hi @boutell , can you please assign this task to me?
Hi @KDrop25 and @adarsh1114, We don't "assign" issues. If you want to work on this issue, go at it! Right now the issue is still open. If you two want to collaborate on this you can, or go ahead and try to create a solution on your own. I'm mostly available here and in our Discord (https://discord.com/invite/HwntQpADJr) channel if you have questions.
Is anyone actively working on this? If not, I'd like to get a try
@eladavn As far as I know, there isn't anybody working on this. You are welcome to give it a go!
Would I be right to assume that the whoami module is not to be extending any other module?
Correct. It would be an endpoint that is implemented by the core apostrophe login module.
I would like to work on this issue
So we have to just implement this GET /api/v1/@apostrophecms/login/whoami or anything else also?
This PR is already close to finished, but we haven't heard from @sombitganguly in a while, and we did ask for a bit more test coverage:
https://github.com/apostrophecms/apostrophe/pull/4872
We haven't heard from @sombitganguly in a while. @niki-commit you could look at completing the work in this PR, see the notes in that conversation:
https://github.com/apostrophecms/apostrophe/pull/4872
@boutell i have made a commit recently, please review kindly
Hi @boutell
I'd love to contribute to this issue if it's still open for work. I saw that the existing PR (#4872) is close to done but might still need additional test coverage or final adjustments. Would it be alright if I pick this up and help bring it over the finish line? Also, if there's anything specific you'd like me to focus on (tests, refactoring, documentation), I'd appreciate any guidance. Thanks!
Closed by PR #4872
@Jenix-YT - We must have been typing at the same time! Sorry, this PR has been completed and closed. Looking at the issues, there is at least one issue marked as "contributions welcomed", PR#4713. But you can take a look at the enhancement tickets and see if there is one you could tackle.
Great work wrapping this up — the whoami endpoint is a big win for headless Apostrophe devs 👏 Thanks @boutell, @BoDonkey, and all contributors for driving it to completion!
I’ll definitely take a look at #4713 and the other enhancement tickets to see where I can jump in next. Looking forward to contributing!
— Bhumit Mittal