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.
- package/dist/service.js +23 -13
- 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
|
-
//
|
|
78
|
-
//
|
|
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
|
-
//
|
|
82
|
-
//
|
|
83
|
-
//
|
|
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
|
-
//
|
|
91
|
-
owner =
|
|
92
|
-
|
|
93
|
-
//
|
|
94
|
-
|
|
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);
|