How to properly wait (via Promise) on a JWT token?
See original GitHub issueI’m using AWS Cognito for authentication, and I’m really confused about how to set it up so AppSync auth waits for Cognito authorization. I have this:
const client = new AWSAppSyncClient(
{
url: process.env.APPSYNC_API_URL,
region: process.env.AWS_REGION,
auth: {
type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
jwtToken: () => store.state.auth.user.idToken,
},
},
{
defaultOptions: {
watchQuery: {
fetchPolicy: 'cache-and-network',
},
},
}
);
This works in most cases, but sometimes there’s a race condition when the AppSync client is ready but the Vuex store doesn’t have the token just yet. Any advice?
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
the tokenGetter method does not wait for the promise to be ...
I have a getToken() method which is checking for token's validity and calling the service for getting new set of tokens. The method...
Read more >Securing Node.js RESTful APIs with JSON Web Tokens(JWT ...
Securing Node.js RESTful APIs using JSON Web Tokens with great ... Try Catch the awaited promise to handle the error try { var...
Read more >Handling JWT in Admin Apps the Right Way - Marmelab
The solution will consist in asking these methods to wait for the end of the possible fetch to the /refresh-token endpoint started by...
Read more >Node js http request await - viviamaviaggia.it
Handling Axios promises using async-await. request to send the data to ... Node js jwt authentication mysql Step 2: Return a JWT token...
Read more >Learn how to handle authentication with Node.js using JWT
JWT (JSON Web Token) is usually used to send information that can be trusted and verified using a digital signature. A user sends...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi,
You can provide an async function that returns a promise containing the token. Here is how you would do it using the Auth module from Amplify:
Hope this helps 😃
I might suggest adding promise resolver function in case of error. This will prevent anything from being printed to the console.log.