@@ -159,7 +159,7 @@ module.exports = function(AV) {
159159 * call linkWith on the user (even if it doesn't exist yet on the server).
160160 * @private
161161 */
162- _linkWith : function ( provider , data ) {
162+ _linkWith : function ( provider , data , { failOnNotExist = false } = { } ) {
163163 var authType ;
164164 if ( _ . isString ( provider ) ) {
165165 authType = provider ;
@@ -170,7 +170,10 @@ module.exports = function(AV) {
170170 if ( data ) {
171171 return this . save (
172172 { authData : { [ authType ] : data } } ,
173- { fetchWhenSave : ! ! this . get ( 'authData' ) }
173+ {
174+ fetchWhenSave : ! ! this . get ( 'authData' ) ,
175+ _failOnNotExist : failOnNotExist ,
176+ }
174177 ) . then ( function ( model ) {
175178 return model . _handleSaveResult ( true ) . then ( function ( ) {
176179 return model ;
@@ -211,7 +214,7 @@ module.exports = function(AV) {
211214 * @param {string } unionId
212215 * @param {Object } [unionLoginOptions]
213216 * @param {string } [unionLoginOptions.unionIdPlatform = 'weixin'] unionId platform
214- * @param {boolean } [unionLoginOptions.asMainAccount = false]
217+ * @param {boolean } [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.
215218 * @return {Promise<AV.User> } A promise that is fulfilled with the user when completed.
216219 * @example user.associateWithAuthDataAndUnionId({
217220 * openid: 'abc123',
@@ -897,6 +900,8 @@ module.exports = function(AV) {
897900 *
898901 * @param {Object } authData The response json data returned from third party token, maybe like { openid: 'abc123', access_token: '123abc', expires_in: 1382686496 }
899902 * @param {string } platform Available platform for sign up.
903+ * @param {Object } [options]
904+ * @param {boolean } [options.failOnNotExist] If true, the login request will fail when no user match this authData exists.
900905 * @return {Promise } A promise that is fulfilled with the user when
901906 * the login completes.
902907 * @example AV.User.signUpOrlogInWithAuthData({
@@ -910,8 +915,8 @@ module.exports = function(AV) {
910915 * });
911916 * @see {@link https://leancloud.cn/docs/js_guide.html#绑定第三方平台账户 }
912917 */
913- signUpOrlogInWithAuthData ( authData , platform ) {
914- return AV . User . _logInWith ( platform , authData ) ;
918+ signUpOrlogInWithAuthData ( authData , platform , options ) {
919+ return AV . User . _logInWith ( platform , authData , options ) ;
915920 } ,
916921
917922 /**
@@ -922,15 +927,16 @@ module.exports = function(AV) {
922927 * @param {string } unionId
923928 * @param {Object } [unionLoginOptions]
924929 * @param {string } [unionLoginOptions.unionIdPlatform = 'weixin'] unionId platform
925- * @param {boolean } [unionLoginOptions.asMainAccount = false]
930+ * @param {boolean } [unionLoginOptions.asMainAccount = false] If true, the unionId will be associated with the user.
931+ * @param {boolean } [options.failOnNotExist] If true, the login request will fail when no user match this authData exists.
926932 * @return {Promise<AV.User> } A promise that is fulfilled with the user when completed.
927933 * @example AV.User.signUpOrlogInWithAuthDataAndUnionId({
928934 * openid: 'abc123',
929935 * access_token: '123abc',
930936 * expires_in: 1382686496
931937 * }, 'weixin', 'union123', {
932938 * unionIdPlatform: 'weixin',
933- * asMainAccount: false ,
939+ * asMainAccount: true ,
934940 * }).then(function(user) {
935941 * //Access user here
936942 * }).catch(function(error) {
@@ -945,7 +951,8 @@ module.exports = function(AV) {
945951 ) {
946952 return this . signUpOrlogInWithAuthData (
947953 mergeUnionDataIntoAuthData ( authData , unionId , unionLoginOptions ) ,
948- platform
954+ platform ,
955+ unionLoginOptions
949956 ) ;
950957 } ,
951958
@@ -1320,9 +1327,9 @@ module.exports = function(AV) {
13201327 }
13211328 } ,
13221329
1323- _logInWith : function ( provider , options ) {
1330+ _logInWith : function ( provider , authData , options ) {
13241331 var user = AV . Object . _create ( '_User' ) ;
1325- return user . _linkWith ( provider , options ) ;
1332+ return user . _linkWith ( provider , authData , options ) ;
13261333 } ,
13271334 }
13281335 ) ;
0 commit comments