amplify-ui: Session Not Found

Before creating a new issue, please confirm:

On which framework/platform are you having an issue?

React

Which UI component?

Liveness

How is your app built?

Webpack

What browsers are you seeing the problem on?

Chrome

Which region are you seeing the problem in?

us-east-1

Please describe your bug.

I can run well with my local cdk nodejs api, however when i deploy api aws and access online api in my frontend, the Liveness component show this error: Session Not Found .

What’s the expected behaviour?

At this point the FacelivenessDetection component should start scanning the face.

Help us reproduce the bug!

similar to https://github.com/aws-amplify/amplify-ui/issues/5043#issue-2170152040, the difference is i use custom credentials provider and my backend is aws cdk. I don’t configure amplify cli becase the use of custom credentials provider. Even i configure amplify, the error still occurs.

Code Snippet

const credentialProvider: AwsCredentialProvider = async () => {
  return Promise.resolve({
    accessKeyId: '',
    secretAccessKey: '',
    sessionToken:
      '',
    expiration: new Date(''),
  });
};

export const AWSFaceLivenessDetector: FC = () => {
  const [loading, setLoading] = useState<boolean>(true);
  const [createLivenessApiData, setCreateLivenessApiData] = useState<{
    sessionId: string;
  } | null>(null);

  const nav = useNavigate();

  console.log('sessionId', createLivenessApiData?.sessionId);

  useEffect(() => {
    const fetchCreateLiveness: () => Promise<void> = async () => {
      /*
       * This should be replaced with a real call to your own backend API
       */
      const response = await request
        .get<any, { sessionId: string }>('https://xxx.com/aws/face/getFaceLivenessSessionId')
        .catch((e: any) => {
          toast.error(typeof e === 'string' ? e : e?.message);
          return null;
        });
      const data = response;

      setCreateLivenessApiData(data);
      setLoading(false);
    };

    fetchCreateLiveness();
  }, []);

  const handleAnalysisComplete: () => Promise<void> = async () => {
    /*
     * This should be replaced with a real call to your own backend API
     */
    const response = await request
      .get<any, { isLive: boolean }>(
        `https://xxx.com/aws/face/getFaceLivenessSessionResults/${createLivenessApiData?.sessionId}`
      )
      .catch((e: any) => {
        toast.error(typeof e === 'string' ? e : e?.message);
        return null;
      });

    const data = response;
    /*
     * Note: The isLive flag is not returned from the GetFaceLivenessSession API
     * This should be returned from your backend based on the score that you
     * get in response. Based on the return value of your API you can determine what to render next.
     * Any next steps from an authorization perspective should happen in your backend and you should not rely
     * on this value for any auth related decisions.
     */
    if (data?.isLive) {
      toast.success('Successfully Verfied');
    } else {
      toast.error('Verification Failed');
    }

    nav('/xhs');
  };

  return (
    <ThemeProvider>
      {loading ? (
        <Loader />
      ) : (
        <FaceLivenessDetectorCore
          sessionId={createLivenessApiData?.sessionId || ''}
          region="us-east-1"
          onAnalysisComplete={handleAnalysisComplete}
          onError={(error: LivenessError) => {
            toast.error(error.error.message);
          }}
          onUserCancel={() => {}}
          config={{ credentialProvider }}
        />
      )}
    </ThemeProvider>
  );
};

Console log output

image

Additional information and screenshots

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

i will try to reproduce a minimum repo tomorrow, much thanks.