Skip to content

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

@TitusEfferian

Description

@TitusEfferian

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions