By using AWS re:Post, you agree to the Terms of Use

AppSync - Cognito: user/pwd not working in jest test - rejectNoUserPool thrown

0

Hello,

I have an AppSync app configured with Cognito authentication. All is working fine for the Amplify frontend. I would like to add some jest integration tests and was hoping to be able to also use user/pwd authentication (found examples using API_KEY but that is not really something I want to add)

I have tried a lot of things and config options but all of them result in

  console.error
    [ERROR] 18:24.753 AuthError -
                Error: Amplify has not been configured correctly.
                The configuration object is missing required auth properties.
                This error is typically caused by one of the following scenarios:

                1. Did you run `amplify push` after adding auth via `amplify add auth`?
                    See https://aws-amplify.github.io/docs/js/authentication#amplify-project-setup for more information

                2. This could also be caused by multiple conflicting versions of amplify packages, see (https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js) for help upgrading Amplify packages.



      at ConsoleLogger.Object.<anonymous>.ConsoleLogger._log (node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts:115:4)
      at ConsoleLogger.Object.<anonymous>.ConsoleLogger.error (node_modules/@aws-amplify/core/src/Logger/ConsoleLogger.ts:174:12)
      at NoUserPoolError.AuthError [as constructor] (node_modules/@aws-amplify/auth/src/Errors.ts:34:10)
      at new NoUserPoolError (node_modules/@aws-amplify/auth/src/Errors.ts:40:3)
      at AuthClass.Object.<anonymous>.AuthClass.rejectNoUserPool (node_modules/@aws-amplify/auth/src/Auth.ts:2248:25)
      at AuthClass.Object.<anonymous>.AuthClass.signIn (node_modules/@aws-amplify/auth/src/Auth.ts:480:16)
      at signIn (test/AnnotationsSpec.ts:44:17)

Before sharing any of the config details (which I am sure would be needed to provide detailed help) is it at all possible to use Appsync with USER_PWD authentication from a jest test? Any examples 'out there'?

Tx!!

Peter

PS using a bunch of curl commands it does work out to send a query to the AppSync app and get the results back

asked 7 months ago134 views
1 Answers
0

Eventually got it working

import Amplify, {Auth, API } from 'aws-amplify';
import {GraphQLResult} from '@aws-amplify/api-graphql';
...
Amplify.configure({
  aws_appsync_graphqlEndpoint: process.env.GRAPHQLURL,
  Auth: {
    region: process.env.AWS_DEFAULT_REGION,
    identityPoolRegion: process.env.AWS_DEFAULT_REGION,
    userPoolId: process.env.USERPOOLID,
    userPoolWebClientId: process.env.CLIENTID,
    Credentials: {
      authenticationFlowType: 'USER_PASSWORD_AUTH',
    }
  }
});

...

const token = await Auth.signIn( process.env.USERID || '', process.env.APPSYNCPWD);
...
const response = (await API.graphql({ query , authMode: 'AMAZON_COGNITO_USER_POOLS', authToken: token} )) as GraphQLResult;
...

Looks more complicated than I would hope is needed, but for now I am going to stick with it

Suggestions to simplify more than welcome!

Tx

Peter

answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions