Skip to content

Commit 0f5f4cb

Browse files
itsramielstocaaro
andauthored
fix(datastore): handle case when getting auth info for expired token users (#13536)
fix: handle case when getting auth info for expired token users Co-authored-by: Aaron S <[email protected]>
1 parent b6de5f9 commit 0f5f4cb

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/datastore/__tests__/subscription.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,34 @@ describe('sync engine subscription module', () => {
126126
),
127127
).toEqual(authInfo);
128128
});
129+
test('owner authorization with no token(expired)', () => {
130+
const authRules = [
131+
{
132+
provider: 'userPools',
133+
ownerField: 'owner',
134+
allow: 'owner',
135+
identityClaim: 'cognito:username',
136+
operations: ['create', 'update', 'delete'],
137+
},
138+
];
139+
const model = generateModelWithAuth(authRules);
140+
141+
const authInfo = {
142+
authMode: 'userPool',
143+
isOwner: false,
144+
};
145+
146+
expect(
147+
// @ts-ignore
148+
SubscriptionProcessor.prototype.getAuthorizationInfo(
149+
model,
150+
USER_CREDENTIALS.auth,
151+
'userPool',
152+
undefined,
153+
'userPool',
154+
),
155+
).toEqual(authInfo);
156+
});
129157
test('owner authorization with public subscription', () => {
130158
const authRules = [
131159
{

packages/datastore/src/sync/processors/subscription.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class SubscriptionProcessor {
205205
: [];
206206

207207
oidcOwnerAuthRules.forEach(ownerAuthRule => {
208-
const ownerValue = oidcTokenPayload[ownerAuthRule.identityClaim];
208+
const ownerValue = oidcTokenPayload?.[ownerAuthRule.identityClaim];
209209
const singleOwner =
210210
model.fields[ownerAuthRule.ownerField]?.isArray !== true;
211211
const isOwnerArgRequired =

0 commit comments

Comments
 (0)