12

The Goal

Launch a React based order form using AWS amplify. Currently fails to submit entries to the database, due to what may be an authentication problem.

I have an AWS Amplify backend that is being used by several front ends - an inventory management system, and a new order form.

The inventory management system has authentication set up (Cognito User Pools, using the withAuthenticator React Component) that requires a user login to access the app. When this is completed successfully, it allows the user to make changes to the database (dynamoDB, with GraphQl), get data from the database etc.

The order form requires no user login, but I still need to submit the form entry to the database. When the form is hosted using Amplify Console and i submit a form entry, I get this error:

Uncaught (in promise) No current user

Has anyone else dealt with this before or something similar? I haven't been able to find any helpful answers to this problem so far.

Thanks for the help!

1
  • 3
    I just had the same issue. Have you found a solution? Commented Apr 4, 2020 at 6:16

1 Answer 1

-1

You must have enabled user authentication as one of the options for the API when you created it with amplify api add. You need to add authentication to your react app then sign in as a registered user before making the API request. The fastest way is with the prebuilt react UI framework.

Install the UI framework with yarn or npm:

yarn add aws-amplify @aws-amplify/ui-react

or

npm i aws-amplify @aws-amplify/ui-react

Then

import React from "react";
import Amplify from "aws-amplify";
import {AmplifyAuthenticator, AmplifySignOut} from "@aws-amplify/ui-react";
import awsconfig from "./aws-exports";

Amplify.configure(awsconfig);

const App = () => (
  <AmplifyAuthenticator>
    <div>
      My App
      <AmplifySignOut />
    </div>
  </AmplifyAuthenticator>
);

See steps and more details in the documentation: https://docs.amplify.aws/ui/auth/authenticator/q/framework/react#installation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.