Skip to content

Update context.me - #865

Open
SharonStrats wants to merge 3 commits into
stagingfrom
fix/context-me
Open

Update context.me#865
SharonStrats wants to merge 3 commits into
stagingfrom
fix/context-me

Conversation

@SharonStrats

Copy link
Copy Markdown
Contributor

When researching an issue we are having with PATCH on the profile card resource, creating lots of logs led to exposing the following small bug.

Note: this did not fix the PATCH issue.

The logs showed the login flow actually entering ensureLoggedIn() and then ensureLoadedProfile(), and they exposed a race where authn.currentUser() was already available but context.me was still empty. So I have added a saveuser call to refresh the context.

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.

🟡 Changes recommended

The newly introduced login/profile race-handling paths are not covered by existing unit tests, increasing the risk of regressions in authentication flow.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR addresses a login/profile-loading race by ensuring the authenticated user is saved into the AuthenticationContext when a session is already active, so downstream code relying on context.me can proceed reliably.

Changes:

  • Call authn.saveUser() when authn.checkUser() indicates an existing logged-in session.
  • In ensureLoadedProfile(), resolve the WebID via context.me or authn.currentUser(), and backfill context.me when missing before loading the profile.
File summaries
File Description
src/login/login.ts Ensures the auth context is populated from existing sessions/current user to avoid context.me being empty during profile load.
Review details

Suppressed comments (1)

src/login/login.ts:209

  • ensureLoadedProfile now falls back to authn.currentUser() and conditionally calls authn.saveUser() to populate context.me; this race-condition behavior change is not covered by tests. Please add a unit test that exercises the scenario where ensureLoggedIn resolves but context.me is still unset while authn.currentUser() returns a user, and assert that the profile load uses that resolved user and updates context accordingly.
    const logInContext = await ensureLoggedIn(context)
    const resolvedMe = logInContext.me || authn.currentUser()
    if (!resolvedMe) {
      throw new Error('Could not log in')
    }
    if (!logInContext.me) {
      authn.saveUser(resolvedMe as any, context)
    }
    context.publicProfile = await loadProfile(resolvedMe)
  • Files reviewed: 1/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/login/login.ts
Prompt: Add a test that checks ensureLoggedIn() calls authn.saveUser() when authn.checkUser() returns a WebID.

Co-authored-by: GPT-5.4 Mini <gpt-5.4-mini@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

2 participants