MrHertal/react-admin-amplify-demo

I am missing something fundamental when trying to remove demo user

Closed this issue · 3 comments

*** moved from main code repo since a demo question

  1. If I comment out the authProvider.getIdentity section in App.js, I get the error,

LoginForm.js:36 Uncaught (in promise) TypeError: Cannot destructure property 'username' of 'userData.data.getUser' as it is null.
at getDemoUser (LoginForm.js:36:1)

and no fields for username/password render.

  1. If I comment out the 'getDemoUser()' and if(!demoUser) return null sections in LoginForm.js, I get a username/password field which then errors to
    'TypeError: Cannot read properties of undefined (reading 'includes')
    at children (App.js:133:1)'.

  2. Originally, missed need to comment out the below, but I get the same error as #2.

// loginPage={LoginPage}

Appreciate any assistance or words of wisdom. Thank you.

Hi,

I cannot reproduce your problem, can you show me your App.js file?

Cheers

yes, thanks. Below:

import { Amplify, API, graphqlOperation, Storage } from "aws-amplify";
import { Admin, Resource } from "react-admin";
import {
buildAuthProvider,
buildDataProvider,
CognitoGroupList,
CognitoUserList,
CognitoUserShow,
} from "react-admin-amplify";
import awsExports from "./aws-exports";
import {
AccountRepresentativeCreate,
AccountRepresentativeEdit,
AccountRepresentativeList,
AccountRepresentativeShow,
} from "./components/AccountRepresentative";
import {
CustomerCreate,
CustomerEdit,
CustomerList,
CustomerShow,
} from "./components/Customer";
import { Dashboard } from "./components/Dashboard";
import {
EmployeeCreate,
EmployeeEdit,
EmployeeList,
EmployeeShow,
} from "./components/Employee";
import { LoginPage } from "./components/LoginPage";
import {
OrderCreate,
OrderEdit,
OrderList,
OrderShow,
} from "./components/Order";
import {
ProductCreate,
ProductEdit,
ProductList,
ProductShow,
} from "./components/Product";
import {
WarehouseCreate,
WarehouseList,
WarehouseShow,
} from "./components/Warehouse";
import * as mutations from "./graphql/mutations";
import * as queries from "./graphql/queries";

Amplify.configure(awsExports);

const authProvider = buildAuthProvider({
authGroups: ["superadmin", "admin", "superuser", "user"],
// authGroups: ["superadmin", "admin"],
});

const dataProvider = buildDataProvider(
{
queries,
mutations,
},
{
storageBucket: awsExports.aws_user_files_s3_bucket,
storageRegion: awsExports.aws_user_files_s3_bucket_region,
enableAdminQueries: true,
}
);

// Get the demo user avatar
// authProvider.getIdentity = async () => {
// try {
// const userData = await API.graphql(
// graphqlOperation(queries.getUser, { id: "demo" })
// );

// const url = await Storage.get(userData.data.getUser.picture.key);

// return {
// id: "demo",
// fullName: "Demo",
// avatar: url,
// };
// } catch (e) {
// console.log(e);
// }
// };

function App() {
return (
<Admin
authProvider={authProvider}
dataProvider={dataProvider}
// loginPage={LoginPage}
dashboard={Dashboard}
>
{(permissions) => [
,
,
,
,
<Resource
name="accountRepresentatives"
options={{ label: "Account Reps" }}
list={AccountRepresentativeList}
show={AccountRepresentativeShow}
edit={AccountRepresentativeEdit}
create={AccountRepresentativeCreate}
/>,
,
permissions.includes("superadmin") ? (
<Resource
name="cognitoUsers"
options={{ label: "Cognito Users" }}
list={CognitoUserList}
show={CognitoUserShow}
/>
) : null,
permissions.includes("superadmin") ? (
<Resource
name="cognitoGroups"
options={{ label: "Cognito Groups" }}
list={CognitoGroupList}
/>
) : null,
]}

);
}

export default App;

Attempted a reinstall and everything is ok. Not sure what I did the first time. All set. Phenomenal work!