Skip to content

feat(website): add GET /users/me endpoint for authenticated user lookup - #1308

Merged
fhennig merged 5 commits into
mainfrom
get-users-me
Jul 7, 2026
Merged

feat(website): add GET /users/me endpoint for authenticated user lookup#1308
fhennig merged 5 commits into
mainfrom
get-users-me

Conversation

@fhennig

@fhennig fhennig commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a new /api/users/me endpoint.

I want to use this, so the seeder can - based on the given API key - find out its own user ID. It can then use this to fetch its own collections.

PR Checklist

  • All necessary documentation has been adapted.
  • The implemented feature is covered by an appropriate test.

Felix Hennig and others added 2 commits July 1, 2026 17:06
Returns the calling user's PublicUser (id + name), resolved from
whichever credential the proxy injected as ?userId. Works with both
session cookies and API keys since the proxy handles auth before
forwarding.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Without this, /api/users/me fell through to the dynamic [id].ts route
which uses proxyToBackendNoAuth — no userId would be injected and the
backend would return 400 (missing required param).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@fhennig fhennig self-assigned this Jul 1, 2026
@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboards Ready Ready Preview, Comment Jul 7, 2026 7:48am

Request Review

@fhennig

fhennig commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

From the backend perspective this is a little bit stupid ... Should this be a frontend only thing?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a “current user” lookup endpoint that can be called via the frontend /api proxy, enabling API-key authenticated clients (e.g., a seeder) to discover their own internal user ID and then fetch user-scoped resources like collections.

Changes:

  • Added a new frontend proxy route GET /api/users/me and a client helper BackendService.getMe().
  • Added a backend endpoint GET /users/me that returns the PublicUser for the injected userId query parameter.
  • Added backend controller tests covering the new endpoint (success + 404).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
website/src/pages/api/users/me.ts Adds /api/users/me route proxying authenticated requests to the backend.
website/src/backendApi/backendService.ts Adds getMe() helper for calling the new endpoint from the frontend client code.
backend/src/main/kotlin/org/genspectrum/dashboardsbackend/controller/UsersController.kt Adds GET /users/me endpoint returning PublicUser.
backend/src/test/kotlin/org/genspectrum/dashboardsbackend/controller/UsersControllerTest.kt Adds tests for GET /users/me success and not-found cases.
backend/src/test/kotlin/org/genspectrum/dashboardsbackend/controller/UsersClient.kt Adds test client helpers to call GET /users/me.

The backend endpoint was redundant — /users/{id} already returns the
same PublicUser shape. The frontend me.ts route now resolves the caller
from context.locals.gsUserId (set by authMiddleware for both session
cookies and API keys) and fetches /users/{id} on the backend directly.
No backend changes required.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread website/src/pages/api/users/me.ts
Comment thread website/src/backendApi/backendService.ts Outdated
Comment thread website/src/backendApi/backendService.ts Outdated
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@fengelniederhammer fengelniederhammer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change the PR title to feat(website) and add an e2e (Playwright) test for the new endpoint?

@fhennig fhennig changed the title feat(backend): add GET /users/me endpoint for authenticated user lookup feat(website): add GET /users/me endpoint for authenticated user lookup Jul 7, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@fengelniederhammer fengelniederhammer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment on lines +11 to +18
test('GET /api/users/me returns user data when authenticated', async ({ authenticatedPage }) => {
const response = await authenticatedPage.request.get('/api/users/me');

expect(response.status()).toBe(200);
const body = (await response.json()) as { id: number; name: string };
expect(typeof body.id).toBe('number');
expect(body.name).toBe('e2e-test');
});
Comment on lines +23 to +29
try {
const response = await fetch(new URL(`/users/${userId}`, getBackendHost()));
return new Response(response.body, {
status: response.status,
headers: response.headers,
});
} catch (error) {
@fhennig
fhennig merged commit ff22ac4 into main Jul 7, 2026
12 checks passed
@fhennig
fhennig deleted the get-users-me branch July 7, 2026 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants