Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 80 additions & 9 deletions src/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ module.exports = function(AV) {
* call linkWith on the user (even if it doesn't exist yet on the server).
* @private
*/
_linkWith: function(provider, data, { failOnNotExist = false } = {}) {
_linkWith: function(
provider,
data,
{ failOnNotExist = false, useMasterKey, sessionToken, user } = {}
) {
var authType;
if (_.isString(provider)) {
authType = provider;
Expand All @@ -157,6 +161,9 @@ module.exports = function(AV) {
return this.save(
{ authData: { [authType]: data } },
{
useMasterKey,
sessionToken,
user,
fetchWhenSave: !!this.get('authData'),
_failOnNotExist: failOnNotExist,
}
Expand Down Expand Up @@ -580,14 +587,22 @@ module.exports = function(AV) {
unionIdPlatform = 'weixin',
asMainAccount = true,
failOnNotExist = false,
useMasterKey,
sessionToken,
user,
} = {}) {
const getAuthInfo = getAdapter('getAuthInfo');
return getAuthInfo({
preferUnionId,
asMainAccount,
platform: unionIdPlatform,
}).then(authInfo =>
this.loginWithMiniApp(authInfo, { failOnNotExist })
this.loginWithMiniApp(authInfo, {
failOnNotExist,
useMasterKey,
sessionToken,
user,
})
);
},

Expand All @@ -602,12 +617,20 @@ module.exports = function(AV) {
unionIdPlatform = 'weixin',
asMainAccount = false,
failOnNotExist = false,
useMasterKey,
sessionToken,
user,
} = {}
) {
const getAuthInfo = getAdapter('getAuthInfo');
return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {
authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });
return this.loginWithMiniApp(authInfo, { failOnNotExist });
return this.loginWithMiniApp(authInfo, {
failOnNotExist,
useMasterKey,
sessionToken,
user,
});
});
},

Expand All @@ -626,6 +649,9 @@ module.exports = function(AV) {
unionIdPlatform = 'qq',
asMainAccount = true,
failOnNotExist = false,
useMasterKey,
sessionToken,
user,
} = {}) {
const getAuthInfo = getAdapter('getAuthInfo');
return getAuthInfo({
Expand All @@ -634,7 +660,12 @@ module.exports = function(AV) {
platform: unionIdPlatform,
}).then(authInfo => {
authInfo.provider = PLATFORM_QQAPP;
return this.loginWithMiniApp(authInfo, { failOnNotExist });
return this.loginWithMiniApp(authInfo, {
failOnNotExist,
useMasterKey,
sessionToken,
user,
});
});
},

Expand All @@ -649,13 +680,21 @@ module.exports = function(AV) {
unionIdPlatform = 'qq',
asMainAccount = false,
failOnNotExist = false,
useMasterKey,
sessionToken,
user,
} = {}
) {
const getAuthInfo = getAdapter('getAuthInfo');
return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {
authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });
authInfo.provider = PLATFORM_QQAPP;
return this.loginWithMiniApp(authInfo, { failOnNotExist });
return this.loginWithMiniApp(authInfo, {
failOnNotExist,
useMasterKey,
sessionToken,
user,
});
});
},

Expand Down Expand Up @@ -1316,14 +1355,22 @@ module.exports = function(AV) {
unionIdPlatform = 'weixin',
asMainAccount = true,
failOnNotExist = false,
useMasterKey,
sessionToken,
user,
} = {}) {
const getAuthInfo = getAdapter('getAuthInfo');
return getAuthInfo({
preferUnionId,
asMainAccount,
platform: unionIdPlatform,
}).then(authInfo =>
this.loginWithMiniApp(authInfo, { failOnNotExist })
this.loginWithMiniApp(authInfo, {
failOnNotExist,
useMasterKey,
sessionToken,
user,
})
);
},

Expand All @@ -1344,12 +1391,20 @@ module.exports = function(AV) {
unionIdPlatform = 'weixin',
asMainAccount = false,
failOnNotExist = false,
useMasterKey,
sessionToken,
user,
} = {}
) {
const getAuthInfo = getAdapter('getAuthInfo');
return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {
authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });
return this.loginWithMiniApp(authInfo, { failOnNotExist });
return this.loginWithMiniApp(authInfo, {
failOnNotExist,
useMasterKey,
sessionToken,
user,
});
});
},

Expand All @@ -1371,6 +1426,9 @@ module.exports = function(AV) {
unionIdPlatform = 'qq',
asMainAccount = true,
failOnNotExist = false,
useMasterKey,
sessionToken,
user,
} = {}) {
const getAuthInfo = getAdapter('getAuthInfo');
return getAuthInfo({
Expand All @@ -1379,7 +1437,12 @@ module.exports = function(AV) {
platform: unionIdPlatform,
}).then(authInfo => {
authInfo.provider = PLATFORM_QQAPP;
return this.loginWithMiniApp(authInfo, { failOnNotExist });
return this.loginWithMiniApp(authInfo, {
failOnNotExist,
useMasterKey,
sessionToken,
user,
});
});
},

Expand All @@ -1401,13 +1464,21 @@ module.exports = function(AV) {
unionIdPlatform = 'qq',
asMainAccount = false,
failOnNotExist = false,
useMasterKey,
sessionToken,
user,
} = {}
) {
const getAuthInfo = getAdapter('getAuthInfo');
return getAuthInfo({ platform: unionIdPlatform }).then(authInfo => {
authInfo = AV.User.mergeUnionId(authInfo, unionId, { asMainAccount });
authInfo.provider = PLATFORM_QQAPP;
return this.loginWithMiniApp(authInfo, { failOnNotExist });
return this.loginWithMiniApp(authInfo, {
failOnNotExist,
useMasterKey,
sessionToken,
user,
});
});
},

Expand Down
2 changes: 1 addition & 1 deletion storage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ export class Role extends Object {
setName(name: string): Role;
}

interface OAuthLoginOptions {
interface OAuthLoginOptions extends AuthOptions {
failOnNotExist?: boolean;
}

Expand Down