I have a simple React Native application that uses Cognito for authentication and in one of the screens I want to show some user attributes associated with the logged in user.
I had this working using the ‘aws-amplify 5.3.x npm package
import { Auth } from 'aws-amplify'
const user = await Auth.currentAuthenticatedUser()
const { sub, name, email, phone_number } = user.attributes
I tried to migrate to v6, which caused an error, so have distilled it down to the simplest example that reproduces the same problem:
import React, { useEffect, useState } from "react";
import { Amplify } from "aws-amplify";
import { Authenticator, useAuthenticator } from "@aws-amplify/ui-react-native";
import {
FetchUserAttributesOutput,
fetchUserAttributes,
} from "aws-amplify/auth";
import { Button, Text, View, StyleSheet } from "react-native";
Amplify.configure({
Auth: {
Cognito: {
userPoolId: "eu-west-2_xxx",
userPoolClientId: "xxx",
identityPoolId: "eu-west-2:xxx",
signUpVerificationMethod: "code",
userAttributes: {
email: {
required: true,
},
phone_number: {
required: true,
},
name: {
required: true,
},
},
allowGuestAccess: false,
},
},
});
const SignOutButton = () => {
const { signOut } = useAuthenticator();
return (
<View style={styles.signOutButton}>
<Button title="Sign Out" onPress={signOut} />
</View>
);
};
const UserProfile = () => {
const [attributes, setAttributes] = useState<FetchUserAttributesOutput>();
useEffect(() => {
fetchUserAttributes().then(setAttributes).catch(console.error);
}, []);
return (
<View style={styles.container}>
<Text style={styles.text}>User Profile</Text>
<Text style={styles.text}>Name: {attributes?.name}</Text>
<Text style={styles.text}>Phone: {attributes?.phone_number}</Text>
<SignOutButton />
</View>
);
};
const App = () => (
<Authenticator.Provider>
<Authenticator>
<UserProfile />
</Authenticator>
</Authenticator.Provider>
);
const styles = StyleSheet.create({
text: {
fontSize: 20,
marginBottom: 20,
},
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
signOutButton: {
alignSelf: "center",
},
});
export default App;
However, when I run this and login it results in a call to https://cognito-identity.eu-west-2.amazonaws.com/
which responds with status code 400 and the error message Token is not from a supported provider of this identity pool.
.