Skip to content

Commit bd877b1

Browse files
committed
fix postgres wrong authData handling on creation
1 parent 0126ed0 commit bd877b1

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

CONTRIBUTING.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ If you are not familiar with Pull Requests and want to know more about them, you
88

99
### Recommended setup:
1010

11-
* [vscode](https://code.visualstudio.com), the popular IDE.
12-
* [Jasmine Test Explorer](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-jasmine-test-adapter), a very practical test exploration plugin which let you run, debug and see the test results inline.
11+
- [vscode](https://code.visualstudio.com), the popular IDE.
12+
- [Jasmine Test Explorer](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-jasmine-test-adapter), a very practical test exploration plugin which let you run, debug and see the test results inline.
1313

1414
### Setting up you local machine:
1515

16-
* [Fork](https://github.com/parse-community/parse-server) this project and clone the fork on your local machine:
16+
- [Fork](https://github.com/parse-community/parse-server) this project and clone the fork on your local machine:
1717

1818
```sh
1919
$ git clone https://github.com/parse-community/parse-server
@@ -29,44 +29,44 @@ Once you have babel running in watch mode, you can start making changes to parse
2929

3030
### Good to know:
3131

32-
* The `lib/` folder is not commited, so never make changes in there.
33-
* Always make changes to files in the `src/` folder.
34-
* All the tests should point to sources in the `lib/` folder.
32+
- The `lib/` folder is not commited, so never make changes in there.
33+
- Always make changes to files in the `src/` folder.
34+
- All the tests should point to sources in the `lib/` folder.
3535

3636
### Troubleshooting:
3737

38-
*Question*: I modify the code in the src folder but it doesn't seem to have any effect.<br/>
39-
*Answer*: Check that `npm run watch` is running
38+
_Question_: I modify the code in the src folder but it doesn't seem to have any effect.<br/>
39+
_Answer_: Check that `npm run watch` is running
4040

41-
*Question*: How do I use breakpoints and debug step by step?<br/>
42-
*Answer*: The easiest way is to install [Jasmine Test Explorer](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-test-explorer), it will let you run selectively tests and debug them.
43-
44-
*Question*: How do I deploy my forked version on my servers?<br/>
45-
*Answer*: In your `package.json`, update the `parse-server` dependency to `https://github.com/MY_USERNAME/parse-server#MY_FEATURE`. Run `npm install`, commit the changes and deploy to your servers.
41+
_Question_: How do I use breakpoints and debug step by step?<br/>
42+
_Answer_: The easiest way is to install [Jasmine Test Explorer](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-test-explorer), it will let you run selectively tests and debug them.
4643

44+
_Question_: How do I deploy my forked version on my servers?<br/>
45+
_Answer_: In your `package.json`, update the `parse-server` dependency to `https://github.com/MY_USERNAME/parse-server#MY_FEATURE`. Run `npm install`, commit the changes and deploy to your servers.
4746

4847
### Please Do's
4948

50-
* Begin by reading the [Development Guide](http://docs.parseplatform.org/parse-server/guide/#development-guide) to learn how to get started running the parse-server.
51-
* Take testing seriously! Aim to increase the test coverage with every pull request. To obtain the test coverage of the project, run: `npm run coverage`
52-
* Run the tests for the file you are working on with the following command: `npm test spec/MyFile.spec.js`
53-
* Run the tests for the whole project to make sure the code passes all tests. This can be done by running the test command for a single file but removing the test file argument. The results can be seen at *<PROJECT_ROOT>/coverage/lcov-report/index.html*.
54-
* Lint your code by running `npm run lint` to make sure the code is not going to be rejected by the CI.
55-
* **Do not** publish the *lib* folder.
49+
- Begin by reading the [Development Guide](http://docs.parseplatform.org/parse-server/guide/#development-guide) to learn how to get started running the parse-server.
50+
- Take testing seriously! Aim to increase the test coverage with every pull request. To obtain the test coverage of the project, run: `npm run coverage`
51+
- Run the tests for the file you are working on with the following command: `npm test spec/MyFile.spec.js`
52+
- Run the tests for the whole project to make sure the code passes all tests. This can be done by running the test command for a single file but removing the test file argument. The results can be seen at _<PROJECT_ROOT>/coverage/lcov-report/index.html_.
53+
- Lint your code by running `npm run lint` to make sure the code is not going to be rejected by the CI.
54+
- **Do not** publish the _lib_ folder.
5655

5756
### Run your tests against Postgres (optional)
5857

5958
If your pull request introduces a change that may affect the storage or retrieval of objects, you may want to make sure it plays nice with Postgres.
6059

61-
* Run the tests against the postgres database with `PARSE_SERVER_TEST_DB=postgres PARSE_SERVER_TEST_DATABASE_URI=postgres://postgres:password@localhost:5432/parse_server_postgres_adapter_test_database npm run testonly`. You'll need to have postgres running on your machine and setup [appropriately](https://github.com/parse-community/parse-server/blob/master/.travis.yml#L43) or use [`Docker`](#run-a-parse-postgres-with-docker).
62-
* The Postgres adapter has a special debugger that traces all the sql commands. You can enable it with setting the environment variable `PARSE_SERVER_LOG_LEVEL=debug`
63-
* If your feature is intended to only work with MongoDB, you should disable PostgreSQL-specific tests with:
60+
- Run the tests against the postgres database with `PARSE_SERVER_TEST_DB=postgres PARSE_SERVER_TEST_DATABASE_URI=postgres://postgres:password@localhost:5432/parse_server_postgres_adapter_test_database npm run testonly`. You'll need to have postgres running on your machine and setup [appropriately](https://github.com/parse-community/parse-server/blob/master/.travis.yml#L43) or use [`Docker`](#run-a-parse-postgres-with-docker).
61+
- The Postgres adapter has a special debugger that traces all the sql commands. You can enable it with setting the environment variable `PARSE_SERVER_LOG_LEVEL=debug`
62+
- If your feature is intended to only work with MongoDB, you should disable PostgreSQL-specific tests with:
6463

6564
- `describe_only_db('mongo')` // will create a `describe` that runs only on mongoDB
6665
- `it_only_db('mongo')` // will make a test that only runs on mongo
6766
- `it_exclude_dbs(['postgres'])` // will make a test that runs against all DB's but postgres
68-
* Similarly, if your feature is intended to only work with PostgreSQL, you should disable MongoDB-specific tests with:
69-
67+
68+
- Similarly, if your feature is intended to only work with PostgreSQL, you should disable MongoDB-specific tests with:
69+
7070
- `describe_only_db('postgres')` // will create a `describe` that runs only on postgres
7171
- `it_only_db('postgres')` // will make a test that only runs on postgres
7272
- `it_exclude_dbs(['mongo'])` // will make a test that runs against all DB's but mongo
@@ -75,9 +75,10 @@ If your pull request introduces a change that may affect the storage or retrieva
7575

7676
[PostGIS images (select one with v2.2 or higher) on docker dashboard](https://hub.docker.com/r/postgis/postgis) is based off of the official [postgres](https://registry.hub.docker.com/_/postgres/) image and will work out-of-the-box (as long as you create a user with the necessary extensions for each of your Parse databases; see below). To launch the compatible Postgres instance, copy and paste the following line into your shell:
7777

78-
```
78+
```sh
7979
docker run -d --name parse-postgres -p 5432:5432 -e POSTGRES_PASSWORD=password --rm postgis/postgis:11-3.0-alpine && sleep 20 && docker exec -it parse-postgres psql -U postgres -c 'CREATE DATABASE parse_server_postgres_adapter_test_database;' && docker exec -it parse-postgres psql -U postgres -c 'CREATE EXTENSION postgis;' -d parse_server_postgres_adapter_test_database && docker exec -it parse-postgres psql -U postgres -c 'CREATE EXTENSION postgis_topology;' -d parse_server_postgres_adapter_test_database
8080
```
81+
8182
To stop the Postgres instance:
8283

8384
```

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ const buildWhereClause = ({ schema, query, index, caseInsensitive }): WhereClaus
272272
continue;
273273
}
274274
}
275-
276275
const authDataMatch = fieldName.match(/^_auth_data_([a-zA-Z0-9_]+)$/);
277276
if (authDataMatch) {
278277
// TODO: Handle querying by _auth_data_provider, authData is stored in authData field
@@ -1234,15 +1233,20 @@ export class PostgresStorageAdapter implements StorageAdapter {
12341233
return;
12351234
}
12361235
var authDataMatch = fieldName.match(/^_auth_data_([a-zA-Z0-9_]+)$/);
1236+
const authDataAlreadyExists = !!object['authData'];
12371237
if (authDataMatch) {
12381238
var provider = authDataMatch[1];
12391239
object['authData'] = object['authData'] || {};
12401240
object['authData'][provider] = object[fieldName];
12411241
delete object[fieldName];
12421242
fieldName = 'authData';
1243+
// Avoid pushing authData multiple times to the
1244+
// postgres query
1245+
if (authDataAlreadyExists) return;
12431246
}
12441247

12451248
columnsArray.push(fieldName);
1249+
12461250
if (!schema.fields[fieldName] && className === '_User') {
12471251
if (
12481252
fieldName === '_email_verify_token' ||
@@ -1729,7 +1733,6 @@ export class PostgresStorageAdapter implements StorageAdapter {
17291733
caseInsensitive,
17301734
});
17311735
values.push(...where.values);
1732-
17331736
const wherePattern = where.pattern.length > 0 ? `WHERE ${where.pattern}` : '';
17341737
const limitPattern = hasLimit ? `LIMIT $${values.length + 1}` : '';
17351738
if (hasLimit) {

0 commit comments

Comments
 (0)