Skip to content

Commit b6b5850

Browse files
committed
Proper JSON update of AuthData
1 parent f69d9b4 commit b6b5850

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

spec/ParseUser.spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ describe('Parse.User testing', () => {
12731273

12741274
// What this means is, only one Parse User can be linked to a
12751275
// particular Facebook account.
1276-
it_exclude_dbs(['postgres'])("link with provider for already linked user", (done) => {
1276+
it("link with provider for already linked user", (done) => {
12771277
var provider = getMockFacebookProvider();
12781278
Parse.User._registerAuthenticationProvider(provider);
12791279
var user = new Parse.User();
@@ -1295,7 +1295,10 @@ describe('Parse.User testing', () => {
12951295
user2.signUp(null, {
12961296
success: function(model) {
12971297
user2._linkWith('facebook', {
1298-
success: fail,
1298+
success: (err) => {
1299+
jfail(err);
1300+
done();
1301+
},
12991302
error: function(model, error) {
13001303
expect(error.code).toEqual(
13011304
Parse.Error.ACCOUNT_ALREADY_LINKED);

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ export class PostgresStorageAdapter {
749749
// This recursively sets the json_object
750750
// Only 1 level deep
751751
let generate = (jsonb, key, value) => {
752-
return `json_object_set_key(${jsonb}, ${key}, ${value})::jsonb`; 
752+
return `json_object_set_key(COALESCE(${jsonb}, '{}'::jsonb), ${key}, ${value})::jsonb`; 
753753
}
754754
let lastKey = `$${index}:name`;
755755
let fieldNameIndex = index;
@@ -758,7 +758,15 @@ export class PostgresStorageAdapter {
758758
let update = Object.keys(fieldValue).reduce((lastKey, key) => {
759759
let str = generate(lastKey, `$${index}::text`, `$${index+1}::jsonb`)
760760
index+=2;
761-
values.push(key, fieldValue[key]);
761+
let value = fieldValue[key];
762+
if (value) {
763+
if (value.__op === 'Delete') {
764+
value = null;
765+
} else {
766+
value = JSON.stringify(value)
767+
}
768+
}
769+
values.push(key, value);
762770
return str;
763771
}, lastKey);
764772
updatePatterns.push(`$${fieldNameIndex}:name = ${update}`);

0 commit comments

Comments
 (0)