Amplify Hub not firing on `auth` events. when running from Custom Domain

0

I have a custom domain purchased with Route 53. My Amplify app has hosting configured to use it in production. I can successfully login to my application from the backend https://prod.appID.amplifyapp.com/ domain. However, when I login attempt to login to https://myCustomDomain.org/ the Amplify Hub listener events never fire.

My app is configured like soo.

App.tsx snippet:


Amplify.configure(updatedAwsConfig); //aws.exports is updated to correctly set oath.redirectSignIn and oauth.redirectSignOut (per AWS docs)
console.log(`Setting Updated Oauth: ${JSON.stringify(updatedAwsConfig.oauth)}`);

Hub.listen('auth', authEventsProcessor);

function App() 
{ 
    //main app page is defined here.

authEventsProcessor definition

export const authEventsProcessor = (data: any) : HubCallback | LegacyCallback => {
//any => {
   console.log(`Processing Auth Event:\n${JSON.stringify(data)}`);
   //console.log(`Processing Auth Event(2):\n ${data}`);
   switch (data.payload.event) {
      case 'signIn':
      case 'cognitoHostedUI':
         console.log('signing in user');
         handleSignInEvent(data.payload.data);
         break;
      case 'signOut':
         handleSignOut();
         console.log('user signed out');
         break;
      /*
      case 'signUp':
         console.log('user signed up');
         break;
      case 'signIn_failure':
      case 'cognitoHostedUI_failure':
         console.log('user sign in failed');
         break;
      case 'configured':
         console.log('the Auth module is configured');
      */
   }
   return data;
};

pakage.json dependency snippet

    "@aws-amplify/core": "^5.8.6",
    "@aws-amplify/ui-react": "^5.3.2",
    "@aws-amplify/ui-react-storage": "^2.3.2",
    "aws-amplify": "^5.3.13",
    "react": "^18.2.0",
    "react-app-polyfill": "^3.0.0",
    "react-dom": "^18.2.0",
    "react-redux": "^8.0.4",
    "react-router-dom": "^6.4.1",
    "react-scripts": "5.0.1",
    "redux-saga": "^1.2.1",
    "tss-react": "^4.3.2",
    "typescript": "^4.8.4",

When I look in my Browser console I never see the 'Processing Auth Event:' line for my custom domain like I do for the amplifyApp.com domain. What's going on? Is this a bug in Amplify?

1 個回答
0
已接受的答案

The main reason for this might be due to the authentication events are not being triggered as expected.

Ensure that your custom domain is configured to allow cross-origin requests, and the CORS settings for the backend services (e.g., APIs) are correctly configured. Cross-origin issues can prevent events from being triggered.

Make sure that the OAuth redirect URIs in your Amplify app are updated to include your custom domain (https://myCustomDomain.org/).

Make sure that you are using the latest versions of the AWS Amplify libraries (@aws-amplify/core, @aws-amplify/ui-react, etc.). Update your dependencies to the latest versions and check if the issue persists.

In case if you are still observing the same issue, then reach out to the AWS Premium Support for further troubleshooting of the same.

AWS
Srinath
已回答 4 個月前
  • Ensure that your custom domain is configured to allow cross-origin requests, and the CORS settings for the backend services (e.g., APIs) are correctly configured. Cross-origin issues can prevent events from being triggered.

    How do I check that?

  • Thank you. Your "answer" turned out to be the tip I needed to figure it out.
    Turned out I had a problem in my configuration. My app is setup to serve from https://www.my-custom-domain.org/ but my Authentication was configured with https://my-custom-domain.org/ so it didn't have the www. part of the URL my browser was visiting. Updating my config w/ the www fixed it.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南