aws-mobile-appsync-sdk-js: Subscription network error
I use OPENID_CONNECT to authenticate and create a subscription which works fine until after a while the accessToken expires and I get a network error.
How should I configure my subscriptions to automatically refresh the token?
My configuration:
appSyncConfig: {
auth: {
type: 'OPENID_CONNECT',
jwtToken: async () => {
const result = await getToken();
if (result) {
return result.accessToken;
}
return undefined;
},
},
}
The subscription:
export const CardSubscriptionGraphQL = gql`
subscription cardSubscription($ownerId: String!) {
onCard(ownerId: $ownerId) {
...card
}
}
${card}
`;
The subscription invocation:
export default graphql(CardSubscriptionGraphQL,
() => {
return {
options: (props) => {
return {
variables: {ownerId: props.ownerId},
};
},
};
}
)(Cards);
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 2
- Comments: 17 (1 by maintainers)
Commits related to this issue
- Updating subscription link to work exactly as Amplify (#616) Fixes: #598 #596 #594 #574 #544 #541 #509 #501 #491 — committed to awslabs/aws-mobile-appsync-sdk-js by elorzafe 3 years ago
@elorzafe Is this something you could help with? Looks like this whole file came along with your work in #484 with the addition of the new real-time native websockets stuff in AppSync (which is awesome btw). Thanks so much for your work on this!
Update after bumping some dependencies and attempting to further isolate the problem, I’m seeing the same error as @wimvdb on the same line.
And again, it is very straight-forward to reproduce on a real device. Happens within a few seconds of re-launching the app (background to foreground app starts only - does not happen on fresh app starts).
I can reproduce this error now consistently on a real device by toggling the wifi on/off and unsubscribing/resubscribing.
also using 2018-05-29, also having this issue
@roni-frantchi sure request.vtl:
{ "version": "2018-05-29", "payload": {} }response.vtl:
#if(${context.identity.sub} != ${context.arguments.ownerId}) $utils.unauthorized() #else null #endI was able to resolve the problem by updating my velocity templates to the latest version from:
“version”: “2017-02-28”, to “version”: “2018-05-29”.
After changing this the connection reconnects automatically after the device goes offline and comes back online. It does take a few minutes before it’s ready to receive new messages and messages that were sent while the connection was not yet established are lost.