Skip to content

feat(website): sync user with backend on login, use internal user ID#1202

Open
fhennig wants to merge 1 commit into
feat/user-tablefrom
feat/user-frontend
Open

feat(website): sync user with backend on login, use internal user ID#1202
fhennig wants to merge 1 commit into
feat/user-tablefrom
feat/user-frontend

Conversation

@fhennig
Copy link
Copy Markdown
Contributor

@fhennig fhennig commented May 6, 2026

resolves #1190

Summary

  • On GitHub login, mapProfileToUser calls POST /users/sync to upsert the user in the backend and stores the returned internal ID as gsUserId in the better-auth session (stateless JWE cookie)
  • If the sync fails, login is aborted (no silent fallback)
  • Replaces the use of the GitHub ID for ownership checks — collections and subscriptions now use the internal numeric user ID throughout
  • Owner name is resolved via GET /users/{id} and displayed on the collection detail page

Changes

Auth & middleware

  • auth.ts: mapProfileToUser syncs user with backend, stores gsUserId (number); throws on failure to abort login
  • authMiddleware.ts: reads gsUserId from session into Astro.locals
  • backendProxy.ts: forwards gsUserId as userId query param

Types & API

  • types/Collection.ts: ownedBy changed from string to number to match backend Long
  • types/PublicUser.ts: new Zod schema for GET /users/{id} response
  • backendService.ts: adds getUser() to resolve owner names server-side
  • pages/api/users/[id].ts: new proxy route for public user lookup

Collection pages

  • Detail page: fetches and displays owner name (falls back to numeric ID on error); ownerName is always a string
  • Edit page: uses gsUserId for ownership check

Tests

  • Unit/browser specs: fix ownedBy from string to number in fixtures
  • E2E tests: sync E2E user via POST /users/sync in beforeAll to obtain internal ID for collection ownership

Notes

This branch depends on the backend changes in feat/user-table (users table, POST /users/sync, GET /users/{id} endpoints).

🤖 Generated with Claude Code

@vercel
Copy link
Copy Markdown

vercel Bot commented May 6, 2026

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

Project Deployment Actions Updated (UTC)
dashboards Ready Ready Preview, Comment May 8, 2026 5:37pm

Request Review

…for ownership

On GitHub login, mapProfileToUser calls POST /users/sync to upsert the user
in the backend and stores the returned internal Long ID as internalUserId in
the better-auth session (stateless JWE cookie). This replaces the previous
use of the GitHub ID for ownership checks on collections and subscriptions.

- auth.ts: async mapProfileToUser syncs user, adds internalUserId additional field
- authMiddleware.ts: reads internalUserId from session user
- backendProxy.ts: forwards internalUserId as userId query param instead of githubId
- Collection.ts: ownedBy changed from string to number to match backend Long
- PublicUser.ts: new Zod schema for GET /users/{id} response
- backendService.ts: adds getUser() to resolve owner names
- pages/api/users/[id].ts: new proxy route for public user lookup
- collection detail/edit pages: use internalUserId for ownership, display owner name
- E2E tests: sync user via POST /users/sync in beforeAll to get internal ID

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

fix(website): fix lint errors in auth.ts and authMiddleware.ts

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

refactor(website): rename internalUserId to gsUserId

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

fix(website): make login fail if backend user sync fails, simplify gsUserId handling

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

fix(website): make ownerName non-optional, simplify collection detail page

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

refactor(website): simplify gsUserId assignment in authMiddleware

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

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

1 participant