amplifyquery 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/service.js +23 -13
  2. package/package.json +1 -1
package/dist/service.js CHANGED
@@ -74,24 +74,34 @@ function getOwnerByAuthMode(authMode) {
74
74
  try {
75
75
  const { username, userId } = yield (0, auth_1.getCurrentUser)();
76
76
  // IMPORTANT:
77
- // Amplify "owner" authorization commonly uses `cognito:username` by default,
78
- // but some projects store `sub` (userId) instead. To avoid "refetch clears list"
79
- // issues when using list-by-owner secondary indexes, we try multiple candidates.
77
+ // In this workspace we standardize on the default Amplify owner claim:
78
+ // `cognito:username` (i.e. `username` from getCurrentUser()).
80
79
  //
81
- // Candidates priority (unique, non-empty):
82
- // - userId (sub)
83
- // - username (cognito:username)
84
- // - legacy `${userId}::${username}` (older patterns)
85
- const canonicalSub = typeof userId === "string" ? userId : "";
80
+ // This prevents a common bug where some records are written with `sub` (userId)
81
+ // while the owner secondary index is queried with `username`, or vice versa,
82
+ // causing refetch to "lose" most items and overwrite cache with a partial list.
86
83
  const canonicalUsername = typeof username === "string" ? username : "";
84
+ const canonicalSub = typeof userId === "string" ? userId : "";
87
85
  const legacyOwner = canonicalSub && canonicalUsername && canonicalUsername !== canonicalSub
88
86
  ? `${canonicalSub}::${canonicalUsername}`
89
87
  : "";
90
- // Keep `owner` for compatibility (used in some create/update paths), prefer sub.
91
- owner = canonicalSub || canonicalUsername;
92
- const candidates = [canonicalSub, canonicalUsername, legacyOwner].filter((v) => typeof v === "string" && v.length > 0);
93
- // De-dupe while preserving order
94
- ownerCandidates = Array.from(new Set(candidates));
88
+ // Preferred owner value for create/update payloads.
89
+ owner = canonicalUsername || canonicalSub;
90
+ // Preferred owner candidates for list-by-owner queries.
91
+ // If username is available, ONLY use username-based owner to keep list results consistent.
92
+ // If username is missing for some reason, fall back to sub to avoid total failure.
93
+ const candidates = canonicalUsername
94
+ ? [canonicalUsername, legacyOwner]
95
+ : [canonicalSub];
96
+ ownerCandidates = Array.from(new Set(candidates.filter((v) => typeof v === "string" && v.length > 0)));
97
+ // Debug: surface the actual Cognito identifiers in dev logs
98
+ (0, config_1.debugLog)(`🍬 Auth identity resolved`, {
99
+ authMode,
100
+ username,
101
+ userId,
102
+ owner,
103
+ ownerCandidates,
104
+ });
95
105
  }
96
106
  catch (error) {
97
107
  console.error("Error getting user authentication info:", error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amplifyquery",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Amplify+Query",
5
5
  "keywords": [
6
6
  "Amplify",