amplify-js: Error using federated sign-in

Do you want to request a feature or report a bug? Report a bug

What is the current behavior? I’m trying to use a federated sign-in, but getting an error: TypeError: Cannot read property 'identityPoolId' of undefined

at Credentials._setCredentialsFromFederation (react-dom.development.js:17306)
at Credentials.set (react-dom.development.js:17306)
at react-dom.development.js:17306
at new Promise (<anonymous>)
at AuthClass.federatedSignIn (react-dom.development.js:17306)
at ProxyComponent._callee$ (_overRest.js:37)
at tryCatch (_iter-define.js:70)
at Generator.invoke [as _invoke] (es6.array.iterator.js:35)
at Generator.prototype.(:1234/anonymous function) [as next] (http://localhost:1234/src.539ec86d.js:4889:21)
at step (_overRest.js:3)

My files: index.tsx

...
import Amplify from 'aws-amplify'

Amplify.configure({
  Auth: {
    identityPoolId: process.env.AWS_IDENTITY_POOL_ID,
    mandatorySignIn: true,
    region: process.env.AWS_REGION,
    userPoolId: process.env.AWS_USER_POOL_ID,
    userPoolWebClientId: process.env.AWS_USER_POOL_CLIENT_ID,

    cookieStorage: {
      domain: process.env.AWS_COOKIE_DOMAIN
    }
  }
})

...

GoogleSignIn.tsx

async federatedSignIn(googleUser: gapi.auth2.GoogleUser) {
    const { id_token, expires_at } = googleUser.getAuthResponse()
    const profile = googleUser.getBasicProfile()
    let user = {
      email: profile.getEmail(),
      name: profile.getName()
    }

    if (
      !Auth ||
      typeof Auth.federatedSignIn !== 'function' ||
      typeof Auth.currentAuthenticatedUser !== 'function'
    ) {
      throw new Error('No Auth module found, please ensure @aws-amplify/auth is imported')
    }

    await Auth.federatedSignIn('google', { token: id_token, expires_at }, user) <- error is happening here

    user = await Auth.currentAuthenticatedUser()
  }

What is the expected behavior? It should sign user in using google token

Which versions of Amplify, and which browser / OS are affected by this issue? Did this work in previous versions? "aws-amplify": "^1.0.2" MacOS: 10.13.6 Google Chrome: 67.0.3396.99

You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 16 (3 by maintainers)

Most upvoted comments

@powerful23

I am getting this issue.

import API from ‘@aws-amplify/api’; import config from ‘…/…/src/aws-exports’

API.configure(config); …

And I get this error.

API - ensure credentials error TypeError: Cannot read property ‘identityPoolId’ of undefined

For those who still with the problem, I just had to call the configure method from the Amplify lib before using the Auth methods. Like that:

import Amplify from 'aws-amplify';
import awsConfig from './src/aws-exports';
Amplify.configure(awsConfig);

I can’t confirm that this is not working for 1.0.8 for us. Our code looks like this:

const identityPoolId = CognitoFederatedIdentityPoolId || process.env.COGNITO_FEDERATED_IDENTITY_POOL_ID
const region = CognitoRegion || process.env.COGNITO_REGION
const userPoolId = CognitoUserPoolId || process.env.COGNITO_USER_POOL_ID
const userPoolWebClientId = CognitoUserPoolClientId || process.env.COGNITO_USER_POOL_CLIENT_ID
const cognitoAuthProvider = CognitoAuthProviderId || process.env.COGNITO_AUTH_PROVIDER_ID

const auth = {
  Auth: {
    identityPoolId,
    region,
    userPoolId,
    userPoolWebClientId,
    mandatorySignIn: false,
  },
}
Logger.debug(auth)
Amplify.configure(auth)

The values for auth are all set regarding to the Logger output. When we then call Auth to get the federatedCredentials with this function here:

export const getFederatedCredentials = async () => {
  let federatedCredentials
  try {
    federatedCredentials = await Auth.currentCredentials()
  } catch (err) {
    Logger.debug('Error getFederatedCredentials: ', err)
  }
  return federatedCredentials
}

We see the following error:

Error getFederatedCredentials:  TypeError: Cannot read property 'identityPoolId' of undefined
    at Credentials.<anonymous> (Credentials.js:177)
    at step (Credentials.js:40)
    at Object.next (Credentials.js:21)
    at Credentials.js:15
    at tryCallTwo (core.js:45)
    at doResolve (core.js:200)
    at new Promise (core.js:66)
    at __awaiter (Credentials.js:11)
    at Credentials._setCredentialsForGuest (Credentials.js:171)
    at Credentials.set (Credentials.js:339)

If we debug and take a look at the Amplify.Auth object, it seems to be empty:

{
currentUserCredentials: function ()
user: null
userPool: null
_cognitoAuthClient: null
_gettingCredPromise:null
__proto__: Object
}

It all works with 1.0.0 but not with any version higher.