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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠