In src/index.js
, Amplify is initiated as below:
import { Amplify } from 'aws-amplify';
import { BrowserRouter } from 'react-router-dom';
Amplify.configure({
Auth: {
userPoolId: process.env.REACT_APP_AWS_COGNITO_USER_POOL_ID,
region: process.env.REACT_APP_AWS_COGNITO_REGION,
userPoolWebClientId: process.env.REACT_APP_AWS_COGNITO_APP_CLIENT_ID,
storage: browserStorage,
authenticationFlowType: 'CUSTOM_AUTH',
},
});
In src/app.jsx
,
import { Auth } from 'aws-amplify';
const App = () => {
const [currentUser, setCurrentUser] = useState('NotChecked');
const [userGroups, setUserGroups] = useState(null);
useEffect(() => {
Auth.currentAuthenticatedUser()
.then(function (result) {
console.log('storage.organizationId: ', result.storage.organizationId);
console.log(' == Auth.currentAuthenticatedUser() result: ', result);
setCurrentUser(result);
const groups =
result.signInUserSession.accessToken.payload['cognito:groups'];
setUserGroups(groups);
})
.catch(function (error) {
console.error(error);
setCurrentUser('NotSignedIn');
});
In the console log:
result.storage.organizationId
is undefined;
However, result
contains storage
, which then contains organizationId
key and the value is an integer;
How can this be possible?
organizationId
is set in local storage in a grand children component of the App
component.