apostrophe icon indicating copy to clipboard operation
apostrophe copied to clipboard

As a headless developer I can access the current user's name, username, etc. easily

Open boutell opened this issue 1 year ago • 11 comments

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]

boutell avatar Nov 20 '24 16:11 boutell

hi can i work on this issue is it still open to work on ?

KDrop25 avatar Nov 25 '24 03:11 KDrop25

hi @boutell , can you please assign this task to me?

adarsh1114 avatar Dec 07 '24 08:12 adarsh1114

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.

BoDonkey avatar Dec 07 '24 11:12 BoDonkey

Is anyone actively working on this? If not, I'd like to get a try

eladavn avatar Feb 13 '25 14:02 eladavn

@eladavn As far as I know, there isn't anybody working on this. You are welcome to give it a go!

BoDonkey avatar Feb 13 '25 16:02 BoDonkey

Would I be right to assume that the whoami module is not to be extending any other module?

eladavn avatar Feb 17 '25 10:02 eladavn

Correct. It would be an endpoint that is implemented by the core apostrophe login module.

BoDonkey avatar Feb 17 '25 13:02 BoDonkey

I would like to work on this issue

sombitganguly avatar Feb 24 '25 14:02 sombitganguly

So we have to just implement this GET /api/v1/@apostrophecms/login/whoami or anything else also?

niki-commit avatar Mar 18 '25 08:03 niki-commit

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

boutell avatar Mar 18 '25 17:03 boutell

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 avatar Apr 10 '25 17:04 boutell

@boutell i have made a commit recently, please review kindly

sombitganguly avatar Jun 27 '25 08:06 sombitganguly

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!

Jenix-YT avatar Jul 17 '25 09:07 Jenix-YT

Closed by PR #4872

BoDonkey avatar Jul 17 '25 09:07 BoDonkey

@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.

BoDonkey avatar Jul 17 '25 09:07 BoDonkey

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

Bhumit9416 avatar Jul 17 '25 11:07 Bhumit9416