Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the currently logged in user #61

Closed
brecht-vermeersch opened this issue Nov 24, 2020 · 10 comments
Closed

Get the currently logged in user #61

brecht-vermeersch opened this issue Nov 24, 2020 · 10 comments

Comments

@brecht-vermeersch
Copy link

How can I get the currently logged in user (piece)?

@abea
Copy link
Contributor

abea commented Nov 24, 2020

Are you looking for all users currently logged in? There could be many. Regardless, I don't think there's a REST API for that as it's not a property on the user document.

@brecht-vermeersch
Copy link
Author

I probably worded my question poorly. When i am using the api as a logged in user, i would like to get all information about that user (the apostrophe-user piece). Thanks in advance!

@brecht-vermeersch
Copy link
Author

In a view on the website i can get that information from data.user

@boutell
Copy link
Contributor

boutell commented Nov 24, 2020 via email

@boutell
Copy link
Contributor

boutell commented Nov 24, 2020 via email

@brecht-vermeersch brecht-vermeersch closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2024
@boutell boutell reopened this Nov 20, 2024
@boutell
Copy link
Contributor

boutell commented Nov 20, 2024

Seeing this ticket has been closed, I do think it's a mistake not to implement it. Headless developers should enjoy parity with what Nunjucks and Astro-based projects have access to. So I'm bringing it back to life.

Since this ticket was written we have added the /api/v1/@apostrophecms/settings API, which can be used to load and store the properties of their user piece that the user is allowed to directly change. But, this API does not return username and email unless configured to allow the user to change them, which I definitely wouldn't recommend without additional design work because of the security risks.

So, I think we should add a separate API to fetch the same information that is always available in the "body data" if Apostrophe is fully rendering the page with Nunjucks:

          aposBodyData.user = {
            title: req.user.title,
            _id: req.user._id,
            username: req.user.username
          };

I think we'd probably implement this one as:

/api/v1/@apostrophecms/user/_me

But I'll discuss with the team.

@boutell
Copy link
Contributor

boutell commented Nov 20, 2024

I think adding the email address to the list also makes sense, and it should be configurable from there.

@boutell
Copy link
Contributor

boutell commented Nov 20, 2024

(Nothing is stopping any developer from writing an apiRoute at project level for this of course, but I agree you shouldn't have to.)

@boutell
Copy link
Contributor

boutell commented Nov 20, 2024

An update: I see this is on the old A2 headless module, where it definitely won't be built. But I'll open a new ticket for current Apostrophe.

@boutell
Copy link
Contributor

boutell commented Nov 20, 2024

See new ticket: apostrophecms/apostrophe#4810

@boutell boutell closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants