Skip to content

Commit b0f084e

Browse files
committed
Gives Uncaught (in promise) TypeError: Cannot read property 'name' of null
at index.js:16 at Array.reduce (<anonymous>) at index.js:16 at index.js:16 at Object.next (index.js:16) at o (index.js:16)
1 parent 5ec5edb commit b0f084e

File tree

16 files changed

+3349
-73
lines changed

16 files changed

+3349
-73
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM node:lts-slim AS node_modules
22
COPY package.json .
3-
RUN npm install --quiet
3+
RUN npm install --silent
44

55
FROM node:lts-slim AS builder
66
COPY package.json .

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,20 @@ This is an example [react-admin](https://marmelab.com/react-admin/) application
66

77
## Available Scripts
88

9-
In the project directory, you can run:
10-
11-
### Full stack: `docker-compose up --quiet-pull --force-recreate --build`
9+
In the project directory, you can run: `docker-compose up --quiet-pull --force-recreate --build`
1210

1311
It will take more time to run the first time, as Docker installs node_modules in a temporary container.
1412

1513
The containers that get started are:
14+
- Webserver (ra-webserver) - Creates the npm-built webserver on port 8080
1615
- Hasura (graphql-engine) - Creates a Hasura instance on port 8081
17-
- Webserver (ra-webserver) - Creates the yarn-started webserver on an Apline Linux instance
1816
- Postgres (postgres) - Database instance
1917
- Flyway (flyway) - Migrates (runs starting SQL) the Postgres container to the state described in your SQL files in `./migrations/sql`
2018
- graphql-migrations - Migrates (sets initial config) the Hasura container to the state described in your metadata.json file in `./migrations/hasura`
2119
- PGTap - Tests the database instance against PGTap SQL as written in `./tests/sql`
2220

2321
Ideally there'd be a container that runs frontend tests for the ra-webserver instance. But I am a backend guy and I don't know how they work.
2422

25-
I quite like this one-liner for killing and recreating everything:
26-
`docker-compose down;docker volume rm $(docker volume ls -q); docker system prune --volumes -f;docker-compose up -d --build --force-recreate`
2723

2824
### Webserver only:
2925

docker-compose.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ services:
4343
HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
4444
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_ADMIN_SECRET}
4545
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: ${HASURA_UNAUTHORIZED_ROLE}
46-
HASURA_GRAPHQL_LOG_LEVEL: warn
46+
HASURA_GRAPHQL_JWT_SECRET: '{"type": "RS256", "jwk_url": "https://www.googleapis.com/service_accounts/v1/jwk/[email protected]", "audience": "react-admin-low-code", "issuer": "https://securetoken.google.com/react-admin-low-code"}'
47+
HASURA_GRAPHQL_LOG_LEVEL: debug
4748
HASURA_GRAPHQL_ENABLED_LOG_TYPES: query-log
4849
graphql-migrations:
4950
image: dvasdekis/hasura-cli-docker:latest

firebase/.firebaserc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "hedgecheap-test"
4+
}
5+
}

firebase/firebase.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"functions": {
3+
"predeploy": [
4+
"npm --prefix \"$RESOURCE_DIR\" run lint"
5+
]
6+
}
7+
}

firebase/functions/.eslintrc.json

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{
2+
"parserOptions": {
3+
// Required for certain syntax usages
4+
"ecmaVersion": 2017
5+
},
6+
"plugins": [
7+
"promise"
8+
],
9+
"extends": "eslint:recommended",
10+
"rules": {
11+
// Removed rule "disallow the use of console" from recommended eslint rules
12+
"no-console": "off",
13+
14+
// Removed rule "disallow multiple spaces in regular expressions" from recommended eslint rules
15+
"no-regex-spaces": "off",
16+
17+
// Removed rule "disallow the use of debugger" from recommended eslint rules
18+
"no-debugger": "off",
19+
20+
// Removed rule "disallow unused variables" from recommended eslint rules
21+
"no-unused-vars": "off",
22+
23+
// Removed rule "disallow mixed spaces and tabs for indentation" from recommended eslint rules
24+
"no-mixed-spaces-and-tabs": "off",
25+
26+
// Removed rule "disallow the use of undeclared variables unless mentioned in /*global */ comments" from recommended eslint rules
27+
"no-undef": "off",
28+
29+
// Warn against template literal placeholder syntax in regular strings
30+
"no-template-curly-in-string": 1,
31+
32+
// Warn if return statements do not either always or never specify values
33+
"consistent-return": 1,
34+
35+
// Warn if no return statements in callbacks of array methods
36+
"array-callback-return": 1,
37+
38+
// Require the use of === and !==
39+
"eqeqeq": 2,
40+
41+
// Disallow the use of alert, confirm, and prompt
42+
"no-alert": 2,
43+
44+
// Disallow the use of arguments.caller or arguments.callee
45+
"no-caller": 2,
46+
47+
// Disallow null comparisons without type-checking operators
48+
"no-eq-null": 2,
49+
50+
// Disallow the use of eval()
51+
"no-eval": 2,
52+
53+
// Warn against extending native types
54+
"no-extend-native": 1,
55+
56+
// Warn against unnecessary calls to .bind()
57+
"no-extra-bind": 1,
58+
59+
// Warn against unnecessary labels
60+
"no-extra-label": 1,
61+
62+
// Disallow leading or trailing decimal points in numeric literals
63+
"no-floating-decimal": 2,
64+
65+
// Warn against shorthand type conversions
66+
"no-implicit-coercion": 1,
67+
68+
// Warn against function declarations and expressions inside loop statements
69+
"no-loop-func": 1,
70+
71+
// Disallow new operators with the Function object
72+
"no-new-func": 2,
73+
74+
// Warn against new operators with the String, Number, and Boolean objects
75+
"no-new-wrappers": 1,
76+
77+
// Disallow throwing literals as exceptions
78+
"no-throw-literal": 2,
79+
80+
// Require using Error objects as Promise rejection reasons
81+
"prefer-promise-reject-errors": 2,
82+
83+
// Enforce “for” loop update clause moving the counter in the right direction
84+
"for-direction": 2,
85+
86+
// Enforce return statements in getters
87+
"getter-return": 2,
88+
89+
// Disallow await inside of loops
90+
"no-await-in-loop": 2,
91+
92+
// Disallow comparing against -0
93+
"no-compare-neg-zero": 2,
94+
95+
// Warn against catch clause parameters from shadowing variables in the outer scope
96+
"no-catch-shadow": 1,
97+
98+
// Disallow identifiers from shadowing restricted names
99+
"no-shadow-restricted-names": 2,
100+
101+
// Enforce return statements in callbacks of array methods
102+
"callback-return": 2,
103+
104+
// Require error handling in callbacks
105+
"handle-callback-err": 2,
106+
107+
// Warn against string concatenation with __dirname and __filename
108+
"no-path-concat": 1,
109+
110+
// Prefer using arrow functions for callbacks
111+
"prefer-arrow-callback": 1,
112+
113+
// Return inside each then() to create readable and reusable Promise chains.
114+
// Forces developers to return console logs and http calls in promises.
115+
"promise/always-return": 2,
116+
117+
//Enforces the use of catch() on un-returned promises
118+
"promise/catch-or-return": 2,
119+
120+
// Warn against nested then() or catch() statements
121+
"promise/no-nesting": 1
122+
}
123+
}

firebase/functions/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

firebase/functions/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
This is where we put Firebase functions
2+
3+
Instructions were sourced from https://hasura.io/blog/authentication-and-authorization-using-hasura-and-firebase/
4+
and are committed to Firebase with console `npm install && firebase deploy --only functions` from a logged-in cmdline version of firebase (installed via npm)
5+
6+
To redeploy firebase functions:
7+
8+
`
9+
gcloud sql users set-password firebase_function_user --instance="your-gcloud-db" --password="firebase_function_password" && firebase --project "react-admin-low-code" functions:config:set database.ip="/cloudsql/hedgecheap-test:us-central1:your-gcloud-db" database.dbname="postgres" database.user="firebase_function_user" database.password="firebase_function_password" database.port=5432 && firebase deploy --only functions
10+
`

firebase/functions/index.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// This is sourced from https://hasura.io/blog/authentication-and-authorization-using-hasura-and-firebase/
2+
// and also https://hasura.io/blog/build-flutter-app-hasura-firebase-part2/
3+
// and is committed to Firebase with console `firebase deploy --only functions`
4+
const functions = require("firebase-functions");
5+
const admin = require("firebase-admin");
6+
const { Pool } = require('pg');
7+
admin.initializeApp(functions.config().firebase);
8+
9+
const pool = new Pool({
10+
user: functions.config().database.user,
11+
host: functions.config().database.ip,
12+
database: functions.config().database.dbname,
13+
password: functions.config().database.password,
14+
port: functions.config().database.port,
15+
});
16+
17+
18+
// On sign up.
19+
exports.processSignUp = functions.auth.user().onCreate(user => {
20+
const customClaims = {
21+
"https://hasura.io/jwt/claims": {
22+
"x-hasura-default-role": "user",
23+
"x-hasura-allowed-roles": ["user"],
24+
"x-hasura-user-id": user.uid
25+
}
26+
};
27+
28+
// Below is only needed if you wish to have Firebase sync its users to a Google Cloud DB
29+
// // Write the new user to the database
30+
// const text = 'INSERT INTO public.users(id, email) VALUES($1, $2)';
31+
// const values = [user.uid, user.email];
32+
// (async () => {
33+
// const client = await pool.connect();
34+
// try {
35+
// const res = await client.query(text, values);
36+
// console.log(res.rows[0])
37+
// } finally {
38+
// // Make sure to release the client before any error handling,
39+
// // just in case the error handling itself throws an error.
40+
// client.release()
41+
// }
42+
// })().catch(err => console.log(err.stack));
43+
44+
return admin
45+
.auth()
46+
.setCustomUserClaims(user.uid, customClaims)
47+
.then(() => {
48+
// Update real-time database to notify client to force refresh.
49+
const metadataRef = admin.database().ref("metadata/" + user.uid);
50+
// Set the refresh time to the current UTC timestamp.
51+
// This will be captured on the client to force a token refresh.
52+
return metadataRef.set({ refreshTime: new Date().getTime() });
53+
}).then
54+
.catch(error => {
55+
console.log(error);
56+
});
57+
});

0 commit comments

Comments
 (0)