Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

f is undefined in fromCognitoIdentityPool #564

Closed
pash90 opened this issue Dec 18, 2019 · 5 comments
Closed

f is undefined in fromCognitoIdentityPool #564

pash90 opened this issue Dec 18, 2019 · 5 comments
Assignees
Labels
bug This issue is a bug.

Comments

@pash90
Copy link

pash90 commented Dec 18, 2019

Describe the bug
While using the fromCognitoIdentityPool function from @aws-sdk/credential-provider-cognito-identity, there is a runtime error that says:

TypeError: f is undefined

image

I understand that this is a library in development but using the v2 aws-sdk is a no-go since the only thing I need is creating credentials for an anonymous user.

SDK version number
v3

Is the issue in the browser/Node.js?
Browser/Node.js

Details of the browser/Node.js version
v12.13.1

To Reproduce (observed behavior)

import { config } from "aws-sdk/global"
import { fromCognitoIdentityPool } from "@aws-sdk/credential-provider-cognito-identity"

export class Authenticator {
  constructor(cognitoIdentityPoolId) {
    this.cognitoIdentityPoolId = cognitoIdentityPoolId;
    config.region = this.cognitoIdentityPoolId.split(':')[0];
  }

  /**
   * @method createAnonymousIdentity
   * Creates a new user for an application.
   */
  async createAnonymousIdentity() {
    const provideCredentials = fromCognitoIdentityPool({
      identityPoolId: this.cognitoIdentityPoolId
    })

    const credentials = await provideCredentials()
    config.credentials = credentials
    config.credentials.getPromise()
    return config.credentials
  }
};

Expected behavior
Ideally, the credentials should be returned at the end.

Screenshots
image

@ajredniwja ajredniwja added the bug This issue is a bug. label Jan 2, 2020
@srchase
Copy link
Contributor

srchase commented Jan 2, 2020

fromCognitoIdentityPool needs to be supplied a CognitoIdentityClient as client in addition to the identityPoolId.

Also, can you provide which the full package versions?

@pash90
Copy link
Author

pash90 commented Jan 14, 2020

@srchase the version I'm using is this one : @aws-sdk/credential-provider-cognito-identity": "0.1.0-preview.2

While you are responding this, could you also guide me as to how to create the CognitoIdentityClient ?

@trivikr trivikr self-assigned this Feb 11, 2020
@AllanZhengYP
Copy link
Contributor

@pash90
Sorry for the delayed reply. You can do:

import {CognitoIdentityClient} from "@aws-sdk/client-cognito-identity";
import { fromCognitoIdentityPool } from "@aws-sdk/credential-provider-cognito-identity"
const provideCredentials = fromCognitoIdentityPool({
    client: new CognitoIdentityClient({})//Or specify the region and other config you need
    identityPoolId: this.cognitoIdentityPoolId
})

@pash90
Copy link
Author

pash90 commented Mar 17, 2020

awesome @AllanFly120 I will try it out asap

@lock
Copy link

lock bot commented Mar 27, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants