question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not getting Identitify pool ID on React Native

See original GitHub issue

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

"aws-amplify": "^4.0.3",
"aws-amplify-react-native": "^5.0.1",

Authentication

Amplify Categories

auth

Environment information

# Put output below this line
System:
    OS: macOS 11.4
    CPU: (8) x64 Apple M1
    Memory: 48.00 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.19.1 - /usr/local/bin/npm
    Watchman: 2021.05.31.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 92.0.4515.131
    Safari: 14.1.1
  npmPackages:
    @babel/core: ~7.9.0 => 7.9.6 (7.9.0)
    @config-plugins/react-native-ble-plx: ^0.0.0 => 0.0.0 
    @expo/vector-icons: ^12.0.0 => 12.0.5 
    @react-native-async-storage/async-storage: ~1.15.0 => 1.15.5 
    @react-native-community/masked-view: 0.1.10 => 0.1.10 
    @react-native-community/netinfo: 6.0.0 => 6.0.0 
    @react-navigation/bottom-tabs: 5.11.2 => 5.11.2 
    @react-navigation/native: ~5.8.10 => 5.8.10 
    @react-navigation/stack: ~5.12.8 => 5.12.8 
    @types/react: ~16.9.35 => 16.9.56 (17.0.8)
    @types/react-native: ~0.63.2 => 0.63.52 
    HelloWorld:  0.0.1 
    amazon-cognito-identity-js: ^5.0.2 => 5.0.2 
    aws-amplify: ^4.0.3 => 4.0.3 
    aws-amplify-react-native: ^5.0.1 => 5.0.1 
    expo: ^42.0.0 => 42.0.1 
    expo-asset: ~8.3.2 => 8.3.2 
    expo-constants: ~11.0.1 => 11.0.1 
    expo-dev-client: ^0.4.4 => 0.4.4 
    expo-font: ~9.2.1 => 9.2.1 
    expo-linear-gradient: ~9.2.0 => 9.2.0 
    expo-linking: ~2.3.1 => 2.3.1 
    expo-location: ~12.1.2 => 12.1.2 
    expo-network: ~3.2.0 => 3.2.0 
    expo-splash-screen: ~0.11.2 => 0.11.2 
    expo-status-bar: ~1.0.4 => 1.0.4 
    expo-updates: ~0.8.1 => 0.8.2 
    expo-web-browser: ~9.2.0 => 9.2.0 
    hermes-inspector-msggen:  1.0.0 
    jest-expo: ^42.0.0 => 42.0.1 
    react: 16.13.1 => 16.13.1 
    react-animated:  0.1.0 
    react-dom: 16.13.1 => 16.13.1 
    react-native: ~0.63.4 => 0.63.4 
    react-native-ble-plx: ^2.0.2 => 2.0.2 
    react-native-dropdown-picker: ^5.1.21 => 5.1.21 
    react-native-gesture-handler: ~1.10.2 => 1.10.3 
    react-native-reanimated: ~2.2.0 => 2.2.0 
    react-native-safe-area-context: 3.2.0 => 3.2.0 
    react-native-screens: ~3.4.0 => 3.4.0 
    react-native-svg: 12.1.1 => 12.1.1 
    react-native-unimodules: ~0.14.5 => 0.14.5 
    react-native-web: ~0.13.12 => 0.13.18 
    typescript: ~4.0.0 => 4.0.7 
  npmGlobalPackages:
    @aws-amplify/cli: 5.3.0
    eas-cli: 0.21.0
    expo-cli: 4.7.3
    npm: 7.19.1
    react-native-cli: 2.0.1
    yarn: 1.22.10



Describe the bug

The users are authenticated with email and password, after that when I run the following code:

  const user = await Auth.currentUserInfo();
  console.log(user)

I get ID as UNDEFINED, this is done in TypeScript for React Native project,

Object { “attributes”: Object { “email”: “rossxxx@verv.energy”, “email_verified”: true, “phone_number”: “+4477719xxxxx”, “phone_number_verified”: false, “sub”: “7ff0136c-92bf-4648-8a52-ff3a9a6b7065”, }, “id”: undefined, “username”: “7ff0136c-92bf-4648-8a52-ff3a9a6b7065”, }

I have already checked the Config file and tested every possible solution, Our code in REACT works fine but not in REACT NATIVE, and we basically have the same code

I wanted to see how I can solve this problem

Expected behavior

Object { “attributes”: Object { “email”: “rossxxx@verv.energy”, “email_verified”: true, “phone_number”: “+4477719xxxxx”, “phone_number_verified”: false, “sub”: “7ff0136c-92bf-4648-8a52-ff3a9a6b7065”, }, “id”: undefined, FIXED HERE “username”: “7ff0136c-92bf-4648-8a52-ff3a9a6b7065”, }

Reproduction steps

After authenticating a user with email and password and running the following code:

  const user = await Auth.currentUserInfo();
  console.log(user)

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line

Object {
  "attributes": Object {
    "email": "rosxxx@verv.energy",
    "email_verified": true,
    "phone_number": "+44777xxx",
    "phone_number_verified": false,
    "sub": "7ff0136c-92bf-4648-8a52-ff3a9a6b7065",
  },
  "id": undefined,
  "username": "7ff0136c-92bf-4648-8a52-ff3a9a6b7065",
}

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

Additional information and screenshots

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
evcodescommented, Aug 30, 2021

I am not able to reproduce this issue and I am going to link a repository with my working code to see if you can find a solution there… You will need to bring in your own Amplify backend by running amplify init to initialize a new amplify project or amplify pull <app-id> to bring in your own backend.

Let me know if this is helpful.

1reaction
evcodescommented, Aug 23, 2021

Hey @sahandmbm ,

Thank you for opening this issue on our repo. I was able to reproduce the same environment you had but did not run into the same issues that you did. Here is my App.js code for a react native project that shows the identity id and identity pool id:


import { StatusBar } from "expo-status-bar";
import React from "react";
import { Auth } from "aws-amplify";
import { Button, StyleSheet, Text, View } from "react-native";

//amplify
import Amplify from "aws-amplify";
import config from "./src/aws-exports";
import { withAuthenticator } from "aws-amplify-react-native";
Amplify.configure(config);

function App() {
  async function showIdentityPool() {
    const user = await (await Auth.currentSession()).getIdToken().payload
    console.log(user["iss"]);
  }
  async function showIdentityId() {
    const user = await Auth.currentUserInfo();
    console.log(user["id"]);
  }

  return (
    <View style={styles.container}>
      <Button onPress={showIdentityId} title="Show Identity Id" />
      <Button onPress={showIdentityPool} title="Show Identity Pool" />
      <StatusBar style="auto" />
    </View>
  );
}

export default withAuthenticator(App);

Maybe you can add an logger to see if something is not properly configured in your application.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS cognito social login throwing NotAuthorizedException ...
I found out the issue, we had Identity pool setup added in the config, so I had to add the social login id's...
Read more >
React Native Signin and Signup with AWS Cognito - Medium
Click on Federated Identities and the in Create new Identity Pool. Provide the name of your project rnCognitoDemo and then select Authentication ...
Read more >
Using identity pools (federated identities) - Amazon Cognito
Amazon Cognito identity pools can support unauthenticated identities by providing a unique identifier and AWS credentials for users who do not authenticate ...
Read more >
Use an existing Cognito User Pool and Identity Pool
Import existing Amazon Cognito resources into your Amplify project. Get started by running amplify import auth command to search for & import an...
Read more >
AWS Amplify + React Native / Authentication FULL SETUP
No minimum fees. Using Amazon Cognito Identity to create a user pool, you pay only for the number of active users per month...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found