Skip to content

Commit c104f5b

Browse files
committed
fix(user): only update the authData of the platform being linking to
this fixes the bug that unionId not being hoisted when another platform already exists.
1 parent deb7afb commit c104f5b

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/user.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ module.exports = function(AV) {
168168
authType = provider.getAuthType();
169169
}
170170
if (data) {
171-
var authData = this.get('authData') || {};
172-
authData[authType] = data;
173-
return this.save({ authData }).then(function(model) {
171+
return this.save(
172+
{ authData: { [authType]: data } },
173+
{ fetchWhenSave: !!this.get('authData') }
174+
).then(function(model) {
174175
return model._handleSaveResult(true).then(function() {
175176
return model;
176177
});
@@ -218,7 +219,7 @@ module.exports = function(AV) {
218219
* expires_in: 1382686496
219220
* }, 'weixin', 'union123', {
220221
* unionIdPlatform: 'weixin',
221-
* asMainAccount: false,
222+
* asMainAccount: true,
222223
* }).then(function(user) {
223224
* //Access user here
224225
* }).catch(function(error) {

test/user.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ describe('User', function() {
206206
const now = Date.now();
207207
return AV.User.signUpOrlogInWithAuthDataAndUnionId(
208208
{
209-
openid: 'openid1' + now,
209+
uid: 'openid1' + now,
210210
access_token: 'access_token',
211211
expires_in: 1382686496,
212212
},
@@ -218,7 +218,7 @@ describe('User', function() {
218218
).then(user1 => {
219219
return AV.User.signUpOrlogInWithAuthDataAndUnionId(
220220
{
221-
openid: 'openid2' + now,
221+
uid: 'openid2' + now,
222222
access_token: 'access_token',
223223
expires_in: 1382686496,
224224
},
@@ -234,15 +234,15 @@ describe('User', function() {
234234
describe('associate with authData', function() {
235235
it('logIn an user, and associate with authData', function() {
236236
var username = Date.now().toString(36);
237-
var password = '123456';
238-
var user = new AV.User();
239-
user.set('username', username);
240-
user.set('password', password);
241-
return user
242-
.save()
243-
.then(function() {
244-
return AV.User.logIn(username, password);
245-
})
237+
238+
return AV.User.signUpOrlogInWithAuthData(
239+
{
240+
uid: 'zaabbbccc123123' + username,
241+
access_token: 'a123123aaabbbbcccc',
242+
expires_in: 1382686496,
243+
},
244+
'test'
245+
)
246246
.then(function(loginedUser) {
247247
return AV.User.associateWithAuthData(loginedUser, 'weixin', {
248248
openid: 'aaabbbccc123123' + username,
@@ -252,10 +252,12 @@ describe('User', function() {
252252
})
253253
.then(user => {
254254
user.get('authData').should.have.property('weixin');
255+
user.get('authData').should.have.property('test');
255256
return user.dissociateAuthData('weixin');
256257
})
257258
.then(user => {
258259
user.get('authData').should.not.have.property('weixin');
260+
user.get('authData').should.have.property('test');
259261
});
260262
});
261263
});

0 commit comments

Comments
 (0)