Self-heal Nuxt UserProfile popup on open, fix schemas/userSchema mismatch - #84
Conversation
|
Important Review available on request
Reviews should be triggered manually for repositories with fewer than 10 stars. Select Trigger review above or comment ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Signed-off-by: janithjay <janithjayashan018@gmail.com>
3b316bc to
31964e9
Compare
| if (res) userProfileState.value = res; | ||
| const res: (UserProfile & {userSchema?: Record<string, AttributeSchema> | null}) | null = await $fetch< | ||
| UserProfile & {userSchema?: Record<string, AttributeSchema> | null} | ||
| >('/api/auth/user/profile'); |
There was a problem hiding this comment.
We may need to move these paths to constants. @coderabbitai can you create an issue for this on https://github.com/thunder-id/thunderid
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
gh issue list \
--repo thunder-id/thunderid \
--state open \
--search 'Nuxt API route paths constants in:title,body' \
--limit 20 \
--json number,title,url,bodyLength of output: 343
🏁 Script executed:
#!/bin/bash
set -euo pipefail
body=$(cat <<'EOF'
## Summary
Extract the Nuxt SDK API route paths into shared constants.
## Rationale
`ThunderIDRoot` uses route string literals for the profile endpoint. Shared constants reduce repeated route strings and prevent route updates from becoming inconsistent across Nuxt runtime modules.
## Affected areas
- `packages/nuxt/src/runtime/components/ThunderIDRoot.ts`
- Other Nuxt runtime components, plugins, middleware, and Nitro handlers that use the same `/api/auth/*` route paths
## Required changes
1. Define and export shared constants for Nuxt SDK API route paths.
2. Replace repeated route string literals with the shared constants.
3. Keep the constants in the appropriate Nuxt package layer. Do not duplicate them across runtime modules.
4. Preserve the current request methods and route behavior.
## Acceptance criteria
- Nuxt API route paths used by more than one runtime module resolve through shared constants.
- `ThunderIDRoot` uses the shared constants for profile fetch and profile update requests.
- No duplicate or inconsistent route path literals remain in the affected Nuxt runtime modules.
- The changes meet the repository ESLint and Prettier requirements.
## Backlinks
- Source pull request: https://github.com/thunder-id/javascript-sdks/pull/84
- Source review comment: https://github.com/thunder-id/javascript-sdks/pull/84#discussion_r3802082276
- Requested by: `@brionmario`
EOF
)
gh issue create \
--repo thunder-id/thunderid \
--title 'Extract Nuxt SDK API route paths into shared constants' \
--body "$body" \
--assignee brionmarioLength of output: 1811
@brionmario, created and assigned thunder-id/thunderid#5060: “Extract Nuxt SDK API route paths into shared constants.”
You are interacting with an AI system.
Purpose
The Nuxt UserProfile popup (
<UserDropdown>→ "Profile") renders blank after a native/embedded sign-in until the page is manually refreshed. Redirect-flow sign-in doesn't show this.Approach
userProfileState/userSchemaStateare populated only during SSR, by thethunderid-ssr.tsNitro plugin - nothing re-fetches them client-side after sign-in. Native sign-in does trigger a full page reload on completion, which should re-run SSR, but the very first SSR pass right after a fresh session is issued can still come back empty.UserDropdown.tsalready had arevalidateProfile()function available fromuseUser()- built for refreshing state after a profile update - but never called it when the popup opens. It calleduseUser()for its side effect only and discarded the result, so the popup just displayed whatever SSR happened to seed, with no way to recover from an empty first pass short of a full page refresh.Changes
components/user/UserDropdown.ts-onProfileClicknow callsrevalidateProfile()on every open, making the popup self-healing regardless of SSR timing.server/routes/auth/user/profile.get.ts- extended to also fetch and returnuserSchema(previously profile-only), so revalidation restores schema-driven fields too, not just raw profile data. Schema-fetch failure doesn't fail the wholeresponse.
components/ThunderIDRoot.ts-revalidateProfile()now updatesuserSchemaStatefrom the extended response, not justuserProfileState.components/user/UserProfile.ts- separate, related bug found while tracing this, destructured aschemasfield fromuseUser()that doesn't exist onUserContextValue(real field isuserSchema), passed toBaseUserProfile's wrong prop. Not the cause of the reported issue (UserDropdownrenders@thunderid/vue'sUserProfiledirectly, not this file), but a real break for anyone using nuxt's standalone<UserProfile>component directly. Also added the missingprofileprop (onlyflattenedProfilewas being passed).After fix
Screen.Recording.2026-08-18.at.1.14.43.PM.mov
Related Issues
Related PRs
Checklist
breaking changelabel added.Security checks