There are lots of blog posts on how to initialize a client.
But they all show very same pattern - client is initialized in render method and jwt token is provided.
And no any examples on how to update a client if jwt token is received later.
Like this one https://itnext.io/integrating-amazon-cognito-authentication-with-the-aws-appsync-graphql-client-4282afb6eee1
render() {
const Navigator = StackNavigator(navigatorConfig);
const signInUserSession = this.props.authData.signInUserSession;
let accessToken = null;
if (signInUserSession) {
accessToken = signInUserSession.accessToken.jwtToken;
console.log(`accessToken = ${accessToken}`);
}
const client = new AWSAppSyncClient({
url: appSyncConfig.graphqlEndpoint,
region: appSyncConfig.region,
auth: {
type: appSyncConfig.authenticationType,
apiKey: appSyncConfig.apiKey,
jwtToken: accessToken
}
});
My question is how to update client if I get toke some times later?
import { Auth } from "aws-amplify"
auth: {
type: AUTH_TYPE.AWS_IAM,
credentials: () => Auth.currentCredentials()
}
make it a function that returns the token, this is my current setup.
Hi @wzup, what @iskanderbroere mention is correct. jwtToken parameter can be assigned to a function that can retrieve the token. Feek free to re open the issue if you still have problems with this.
Thanks @iskanderbroere you saved my day
Most helpful comment
make it a function that returns the token, this is my current setup.