@@ -1353,11 +1353,26 @@ fireauth.Auth.prototype.getIdTokenInternal = function(opt_forceRefresh) {
1353
1353
1354
1354
1355
1355
/**
1356
- * Sign in using a custom token (Bring Your Own Auth) .
1356
+ * Signs in a user asynchronously using a custom token .
1357
1357
* @param {string } token The custom token to sign in with.
1358
1358
* @return {!goog.Promise<!fireauth.AuthUser> }
1359
1359
*/
1360
1360
fireauth . Auth . prototype . signInWithCustomToken = function ( token ) {
1361
+ // Get signInAndRetrieveDataWithCustomToken result and return the user only.
1362
+ return this . signInAndRetrieveDataWithCustomToken ( token )
1363
+ . then ( function ( result ) {
1364
+ return result [ 'user' ] ;
1365
+ } ) ;
1366
+ } ;
1367
+
1368
+
1369
+ /**
1370
+ * Signs in a user asynchronously using a custom token and returns any
1371
+ * additional user info data or credentials returned form the backend.
1372
+ * @param {string } token The custom token to sign in with.
1373
+ * @return {!goog.Promise<!fireauth.AuthEventManager.Result> }
1374
+ */
1375
+ fireauth . Auth . prototype . signInAndRetrieveDataWithCustomToken = function ( token ) {
1361
1376
var self = this ;
1362
1377
// Wait for the redirect state to be determined before proceeding. If critical
1363
1378
// errors like web storage unsupported are detected, fail before RPC, instead
@@ -1371,20 +1386,20 @@ fireauth.Auth.prototype.signInWithCustomToken = function(token) {
1371
1386
// response will look like an anonymous user (no credentials visible).
1372
1387
user . updateProperty ( 'isAnonymous' , false ) ;
1373
1388
// Save isAnonymous flag changes to current user in storage.
1374
- return self . handleUserStateChange_ ( user ) ;
1375
- } ) . then ( function ( ) {
1376
- return self . currentUser_ ( ) ;
1389
+ self . handleUserStateChange_ ( user ) ;
1390
+ return result ;
1377
1391
} ) ;
1378
1392
} ;
1379
1393
1380
1394
1381
1395
/**
1382
- * Sign in using an email and password.
1396
+ * Sign in using an email and password and returns any additional user info
1397
+ * data or credentials returned form the backend.
1383
1398
* @param {string } email The email to sign in with.
1384
1399
* @param {string } password The password to sign in with.
1385
- * @return {!goog.Promise<!fireauth.AuthUser > }
1400
+ * @return {!goog.Promise<!fireauth.AuthEventManager.Result > }
1386
1401
*/
1387
- fireauth . Auth . prototype . signInWithEmailAndPassword =
1402
+ fireauth . Auth . prototype . signInAndRetrieveDataWithEmailAndPassword =
1388
1403
function ( email , password ) {
1389
1404
var self = this ;
1390
1405
// Wait for the redirect state to be determined before proceeding. If critical
@@ -1393,12 +1408,27 @@ fireauth.Auth.prototype.signInWithEmailAndPassword =
1393
1408
return this . redirectStateIsReady_ . then ( function ( ) {
1394
1409
return self . signInWithIdTokenProvider_ (
1395
1410
self . getRpcHandler ( ) . verifyPassword ( email , password ) ) ;
1396
- } ) . then ( function ( result ) {
1397
- return result [ 'user' ] ;
1398
1411
} ) ;
1399
1412
} ;
1400
1413
1401
1414
1415
+ /**
1416
+ * Sign in using an email and password.
1417
+ * @param {string } email The email to sign in with.
1418
+ * @param {string } password The password to sign in with.
1419
+ * @return {!goog.Promise<!fireauth.AuthUser> }
1420
+ */
1421
+ fireauth . Auth . prototype . signInWithEmailAndPassword =
1422
+ function ( email , password ) {
1423
+ // Get signInAndRetrieveDataWithEmailAndPassword result and return
1424
+ // the user only.
1425
+ return this . signInAndRetrieveDataWithEmailAndPassword ( email , password )
1426
+ . then ( function ( result ) {
1427
+ return result [ 'user' ] ;
1428
+ } ) ;
1429
+ } ;
1430
+
1431
+
1402
1432
/**
1403
1433
* Create a new email and password account.
1404
1434
* @param {string } email The email to sign up with.
@@ -1407,15 +1437,31 @@ fireauth.Auth.prototype.signInWithEmailAndPassword =
1407
1437
*/
1408
1438
fireauth . Auth . prototype . createUserWithEmailAndPassword =
1409
1439
function ( email , password ) {
1440
+ // Get createUserAndRetrieveDataWithEmailAndPassword result and return
1441
+ // the user only.
1442
+ return this . createUserAndRetrieveDataWithEmailAndPassword ( email , password )
1443
+ . then ( function ( result ) {
1444
+ return result [ 'user' ] ;
1445
+ } ) ;
1446
+ } ;
1447
+
1448
+
1449
+ /**
1450
+ * Creates a new email and password account and returns any additional user
1451
+ * info data or credentials returned form the backend.
1452
+ * @param {string } email The email to sign up with.
1453
+ * @param {string } password The password to sign up with.
1454
+ * @return {!goog.Promise<!fireauth.AuthEventManager.Result> }
1455
+ */
1456
+ fireauth . Auth . prototype . createUserAndRetrieveDataWithEmailAndPassword =
1457
+ function ( email , password ) {
1410
1458
var self = this ;
1411
1459
// Wait for the redirect state to be determined before proceeding. If critical
1412
1460
// errors like web storage unsupported are detected, fail before RPC, instead
1413
1461
// of after.
1414
1462
return this . redirectStateIsReady_ . then ( function ( ) {
1415
1463
return self . signInWithIdTokenProvider_ (
1416
1464
self . getRpcHandler ( ) . createAccount ( email , password ) ) ;
1417
- } ) . then ( function ( result ) {
1418
- return result [ 'user' ] ;
1419
1465
} ) ;
1420
1466
} ;
1421
1467
@@ -1457,10 +1503,24 @@ fireauth.Auth.prototype.signInAndRetrieveDataWithCredential =
1457
1503
1458
1504
1459
1505
/**
1460
- * Sign in using anonymously a user.
1506
+ * Signs in a user anonymously .
1461
1507
* @return {!goog.Promise<!fireauth.AuthUser> }
1462
1508
*/
1463
1509
fireauth . Auth . prototype . signInAnonymously = function ( ) {
1510
+ // Get signInAnonymouslyAndRetrieveData result and return the user only.
1511
+ return this . signInAnonymouslyAndRetrieveData ( )
1512
+ . then ( function ( result ) {
1513
+ return result [ 'user' ] ;
1514
+ } ) ;
1515
+ } ;
1516
+
1517
+
1518
+ /**
1519
+ * Signs in a user anonymously and returns any additional user info data or
1520
+ * credentials returned form the backend.
1521
+ * @return {!goog.Promise<!fireauth.AuthEventManager.Result> }
1522
+ */
1523
+ fireauth . Auth . prototype . signInAnonymouslyAndRetrieveData = function ( ) {
1464
1524
var self = this ;
1465
1525
// Wait for the redirect state to be determined before proceeding. If critical
1466
1526
// errors like web storage unsupported are detected, fail before RPC, instead
@@ -1469,7 +1529,20 @@ fireauth.Auth.prototype.signInAnonymously = function() {
1469
1529
var user = self . currentUser_ ( ) ;
1470
1530
// If an anonymous user is already signed in, no need to sign him again.
1471
1531
if ( user && user [ 'isAnonymous' ] ) {
1472
- return user ;
1532
+ var additionalUserInfo = fireauth . object . makeReadonlyCopy ( {
1533
+ 'providerId' : null ,
1534
+ 'isNewUser' : false
1535
+ } ) ;
1536
+ return fireauth . object . makeReadonlyCopy ( {
1537
+ // Return the signed in user reference.
1538
+ 'user' : user ,
1539
+ // Do not return credential for anonymous user.
1540
+ 'credential' : null ,
1541
+ // Return any additional IdP data.
1542
+ 'additionalUserInfo' : additionalUserInfo ,
1543
+ // Sign in operation type.
1544
+ 'operationType' : fireauth . constants . OperationType . SIGN_IN
1545
+ } ) ;
1473
1546
} else {
1474
1547
// No anonymous user currently signed in.
1475
1548
return self . signInWithIdTokenProvider_ (
@@ -1484,9 +1557,8 @@ fireauth.Auth.prototype.signInAnonymously = function() {
1484
1557
// overwrites.
1485
1558
user . updateProperty ( 'isAnonymous' , true ) ;
1486
1559
// Save isAnonymous flag changes to current user in storage.
1487
- return self . handleUserStateChange_ ( user ) ;
1488
- } ) . then ( function ( ) {
1489
- return self . currentUser_ ( ) ;
1560
+ self . handleUserStateChange_ ( user ) ;
1561
+ return result ;
1490
1562
} ) ;
1491
1563
}
1492
1564
} ) ;
0 commit comments