@@ -229,6 +229,7 @@ RestWrite.prototype.handleFacebookAuthData = function() {
229229 this . className ,
230230 { 'authData.facebook.id' : facebookData . id } , { } ) ;
231231 } ) . then ( ( results ) => {
232+ this . storage [ 'authProvider' ] = "facebook" ;
232233 if ( results . length > 0 ) {
233234 if ( ! this . query ) {
234235 // We're signing up, but this user already exists. Short-circuit
@@ -237,6 +238,7 @@ RestWrite.prototype.handleFacebookAuthData = function() {
237238 response : results [ 0 ] ,
238239 location : this . location ( )
239240 } ;
241+ this . data . objectId = results [ 0 ] . objectId ;
240242 return ;
241243 }
242244
@@ -249,6 +251,8 @@ RestWrite.prototype.handleFacebookAuthData = function() {
249251 // We're trying to create a duplicate FB auth. Forbid it
250252 throw new Parse . Error ( Parse . Error . ACCOUNT_ALREADY_LINKED ,
251253 'this auth is already used' ) ;
254+ } else {
255+ this . data . username = rack ( ) ;
252256 }
253257
254258 // This FB auth does not already exist, so transform it to a
@@ -262,7 +266,7 @@ RestWrite.prototype.handleFacebookAuthData = function() {
262266
263267// The non-third-party parts of User transformation
264268RestWrite . prototype . transformUser = function ( ) {
265- if ( this . response || this . className !== '_User' ) {
269+ if ( this . className !== '_User' ) {
266270 return ;
267271 }
268272
@@ -272,7 +276,8 @@ RestWrite.prototype.transformUser = function() {
272276 var token = 'r:' + rack ( ) ;
273277 this . storage [ 'token' ] = token ;
274278 promise = promise . then ( ( ) => {
275- // TODO: Proper createdWith options, pass installationId
279+ var expiresAt = new Date ( ) ;
280+ expiresAt . setFullYear ( expiresAt . getFullYear ( ) + 1 ) ;
276281 var sessionData = {
277282 sessionToken : token ,
278283 user : {
@@ -282,10 +287,15 @@ RestWrite.prototype.transformUser = function() {
282287 } ,
283288 createdWith : {
284289 'action' : 'login' ,
285- 'authProvider' : 'password'
290+ 'authProvider' : this . storage [ 'authProvider' ] || 'password'
286291 } ,
287- restricted : false
292+ restricted : false ,
293+ installationId : this . data . installationId ,
294+ expiresAt : Parse . _encode ( expiresAt )
288295 } ;
296+ if ( this . response && this . response . response ) {
297+ this . response . response . sessionToken = token ;
298+ }
289299 var create = new RestWrite ( this . config , Auth . master ( this . config ) ,
290300 '_Session' , null , sessionData ) ;
291301 return create . execute ( ) ;
@@ -404,6 +414,8 @@ RestWrite.prototype.handleSession = function() {
404414
405415 if ( ! this . query && ! this . auth . isMaster ) {
406416 var token = 'r:' + rack ( ) ;
417+ var expiresAt = new Date ( ) ;
418+ expiresAt . setFullYear ( expiresAt . getFullYear ( ) + 1 ) ;
407419 var sessionData = {
408420 sessionToken : token ,
409421 user : {
@@ -415,7 +427,7 @@ RestWrite.prototype.handleSession = function() {
415427 'action' : 'create'
416428 } ,
417429 restricted : true ,
418- expiresAt : 0
430+ expiresAt : Parse . _encode ( expiresAt )
419431 } ;
420432 for ( var key in this . data ) {
421433 if ( key == 'objectId' ) {
0 commit comments