aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

issue with "AWS_IAM as default Authmode for Appsync API"in next js (ssr) #7983

Closed shweta-codeprism closed 3 years ago

shweta-codeprism commented 3 years ago

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

GraphQL API

Amplify Categories

auth

Environment information

``` System: OS: Windows 10 10.0.18363 CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz Memory: 576.67 MB / 7.78 GB Binaries: Node: 12.18.3 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.14.6 - C:\Program Files\nodejs\npm.CMD Browsers: Chrome: 89.0.4389.90 Edge: Spartan (44.18362.449.0) Internet Explorer: 11.0.18362.1 npmPackages: @babel/plugin-proposal-nullish-coalescing-operator: ^7.13.8 => 7.13.8 @babel/plugin-proposal-optional-chaining: ^7.13.8 => 7.13.8 @zeit/next-bundle-analyzer: ^0.1.2 => 0.1.2 autoprefixer: ^9.8.6 => 9.8.6 aws-amplify: ^3.3.24 => 3.3.24 aws-appsync: ^1.4.0 => 1.8.1 babel-plugin-module-resolver: ^4.1.0 => 4.1.0 classnames: ^2.2.6 => 2.2.6 graphql-tag: ^2.10.0 => 2.11.0 lscache: ^1.3.0 => 1.3.0 next: ^9.5.5 => 9.5.5 next-pwa: ^3.1.5 => 3.1.5 next-redux-wrapper: ^6.0.2 => 6.0.2 postcss-cli: ^7.1.2 => 7.1.2 postcss-preset-env: ^6.7.0 => 6.7.0 react: ^16.14.0 => 16.14.0 react-dom: ^16.14.0 => 16.14.0 react-redux: ^7.2.2 => 7.2.2 react-slick: ^0.27.14 => 0.27.14 redux: ^4.0.5 => 4.0.5 redux-devtools-extension: ^2.13.9 => 2.13.9 redux-thunk: ^2.3.0 => 2.3.0 sass: ^1.32.8 => 1.32.8 semantic-ui-css: ^2.4.1 => 2.4.1 semantic-ui-react: ^1.3.1 => 1.3.1 slick-carousel: ^1.8.1 => 1.8.1 tailwindcss: ^1.9.6 => 1.9.6 uuid: ^3.3.2 => 3.4.0 npmGlobalPackages: @angular/cli: 11.0.7 @aws-amplify/cli: 4.42.0 amplify-category-video: 3.1.0 amplify: 0.0.11 aws-amplify: 3.3.20 express-generator: 4.16.1 ng: 0.0.0 nodemon: 2.0.4 now: 20.0.0 ```

Describe the bug

I am using NextJS. And have set AWS_IAM as the default Authentication mode. When I am querying data as follows:

    const data= await API.graphql({
      query: list****
    });

in getStaticProps(), its throwing error

Error: No credentials.

However, it works fine for getStaticPaths().

Expected behavior

As AWS_IAM is the default authMode, it should give me the list result back just like in getStaticPaths.

Reproduction steps

  1. Install amplify and other required packages.
  2. set AWS_IAM as default authMode
  3. In the schema allow iam access ( use @aws_iam with the model)
  4. Fetch list using amplify API

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

dsypniewski commented 3 years ago

I'm having the same problem while trying to use @aws-amplify/api-graphql package in lambda with IAM authentication. After some code hunting it seems to me that handling of AWS_IAM credentials from AWS.config.credentials was lost with version 761a88433d7d49e2cf5d3ae81b12bc40060957fa while this version a047ce73abe98c3bf82e888c3afb4d2f911805f3 still had code responsible for reading credentials from AWS.config.credentials. It seems to me that the Auth module used later on just doesn't care about those unless I'm missing something.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 3 years ago

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

chrisbonifacio commented 3 years ago

Hi :wave: Sorry this was auto-closed by stale bot. We are working towards preventing this from happening in the future. Please let us know if you are still experiencing this issue and in need of assistance.

chrisbonifacio commented 3 years ago

Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you. Thank you!

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.