docs icon indicating copy to clipboard operation
docs copied to clipboard

[content issue]: missing `async` in the example that needed await function

Open TitusEfferian opened this issue 7 months ago • 1 comments

Describe the content issue: In the Required for Multi-Page Applications: Complete External Sign-In After Redirect section, there is a snippet of code:

Hub.listen("auth", ({ payload }) => {
  switch (payload.event) {
    case "signInWithRedirect":
      const user = await getCurrentUser();
      const userAttributes = await fetchUserAttributes();
      console.log({user, userAttributes});
      break;
    case "signInWithRedirect_failure":
      // handle sign in failure
      break;
    case "customOAuthState":
      const state = payload.data; // this will be customState provided on signInWithRedirect function
      console.log(state);
      break;
  }
});

This will not work, as I tried it in my ongoing project and realized that there is an error:

'await' expressions are only allowed within async functions and at the top levels of modules.ts(1308)
page.tsx(41, 43): Did you mean to mark this function as 'async'?

Since there is an await function, we need to define the function as async.

URL page where content issue is: https://docs.amplify.aws/react/build-a-backend/auth/concepts/external-identity-providers/#required-for-multi-page-applications-complete-external-sign-in-after-redirect

TitusEfferian avatar Jun 13 '25 14:06 TitusEfferian

In case this is a valid issue, here is my pull request: https://github.com/aws-amplify/docs/pull/8365

TitusEfferian avatar Jun 13 '25 14:06 TitusEfferian

Thanks @TitusEfferian for both identifying and solving this problem - we've merged your PR #8365 and are closing this issue!

osama-rizk avatar Jun 23 '25 10:06 osama-rizk