0
votes

I've published my React application to amplify, everything went fine there. But when I open the amplify URL I see that no items have been fetched from database and I have an error in console saying "No credentials"

I think the problem lies with the AppSync API somehow. I made it using the Amplify CLI, it uses API key authentication.

Locally I provide credentials using the generated file aws-exports.js. I Import this in my index.tsx like so:

import awsmobile from "./aws-exports";

Amplify.configure(awsmobile);

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);

But this file is not pushed to git, so Amplify obviously doesn't have this from the repo. But I assumed that it was able to generate its own aws-exports.js file, as it doesn't give any errors on the import.

So, what am I missing here? Do I have to use another method for authentication on my AppSync api or what is wrong here? Thanks!

1

1 Answers

0
votes

I think I might have found the solution.

I simply had to annotate my schema.graphql with @aws_api_key like so:

type Item @model @aws_api_key {
  id: ID!
  name: String
}

and of course any custom mutations and subscriptions you have defined aswell.

See: https://aws.amazon.com/blogs/mobile/graphql-security-appsync-amplify/