@@ -247,6 +247,10 @@ function showMultiFactorStatus(activeUser) {
247
247
const label = info && ( info . displayName || info . uid ) ;
248
248
if ( label ) {
249
249
$ ( '#enrolled-factors-drop-down' ) . removeClass ( 'open' ) ;
250
+ // Set the last user, in case the current user is logged out.
251
+ // This can happen if the MFA option being unenrolled is the one that was most recently enrolled into.
252
+ // See - https://github.com/firebase/firebase-js-sdk/issues/3233
253
+ setLastUser ( activeUser ) ;
250
254
mfaUser . unenroll ( info ) . then ( ( ) => {
251
255
refreshUserData ( ) ;
252
256
alertSuccess ( 'Multi-factor successfully unenrolled.' ) ;
@@ -278,6 +282,9 @@ function onAuthError(error) {
278
282
handleMultiFactorSignIn ( getMultiFactorResolver ( auth , error ) ) ;
279
283
} else {
280
284
alertError ( 'Error: ' + error . code ) ;
285
+ if ( error . code === 'auth/user-token-expired' ) {
286
+ alertError ( 'Token expired, please reauthenticate.' ) ;
287
+ }
281
288
}
282
289
}
283
290
@@ -403,13 +410,41 @@ function onLinkWithEmailLink() {
403
410
* Re-authenticate a user with email link credential.
404
411
*/
405
412
function onReauthenticateWithEmailLink ( ) {
413
+ if ( ! activeUser ( ) ) {
414
+ alertError (
415
+ 'No user logged in. Select the "Last User" tab to reauth the previous user.'
416
+ ) ;
417
+ return ;
418
+ }
406
419
const email = $ ( '#link-with-email-link-email' ) . val ( ) ;
407
420
const link = $ ( '#link-with-email-link-link' ) . val ( ) || undefined ;
408
421
const credential = EmailAuthProvider . credentialWithLink ( email , link ) ;
422
+ // This will not set auth.currentUser to lastUser if the lastUser is reauthenticated.
409
423
reauthenticateWithCredential ( activeUser ( ) , credential ) . then ( result => {
410
424
logAdditionalUserInfo ( result ) ;
411
425
refreshUserData ( ) ;
412
- alertSuccess ( 'User reauthenticated!' ) ;
426
+ alertSuccess ( 'User reauthenticated with email link!' ) ;
427
+ } , onAuthError ) ;
428
+ }
429
+
430
+ /**
431
+ * Re-authenticate a user with email and password.
432
+ */
433
+ function onReauthenticateWithEmailAndPassword ( ) {
434
+ if ( ! activeUser ( ) ) {
435
+ alertError (
436
+ 'No user logged in. Select the "Last User" tab to reauth the previous user.'
437
+ ) ;
438
+ return ;
439
+ }
440
+ const email = $ ( '#signin-email' ) . val ( ) ;
441
+ const password = $ ( '#signin-password' ) . val ( ) ;
442
+ const credential = EmailAuthProvider . credential ( email , password ) ;
443
+ // This will not set auth.currentUser to lastUser if the lastUser is reauthenticated.
444
+ reauthenticateWithCredential ( activeUser ( ) , credential ) . then ( result => {
445
+ logAdditionalUserInfo ( result ) ;
446
+ refreshUserData ( ) ;
447
+ alertSuccess ( 'User reauthenticated with email/password!' ) ;
413
448
} , onAuthError ) ;
414
449
}
415
450
@@ -1264,7 +1299,9 @@ function signInWithPopupRedirect(provider) {
1264
1299
break ;
1265
1300
case 'reauthenticate' :
1266
1301
if ( ! activeUser ( ) ) {
1267
- alertError ( 'No user logged in.' ) ;
1302
+ alertError (
1303
+ 'No user logged in. Select the "Last User" tab to reauth the previous user.'
1304
+ ) ;
1268
1305
return ;
1269
1306
}
1270
1307
inst = activeUser ( ) ;
@@ -1860,6 +1897,9 @@ function initApp() {
1860
1897
// Actions listeners.
1861
1898
$ ( '#sign-up-with-email-and-password' ) . click ( onSignUp ) ;
1862
1899
$ ( '#sign-in-with-email-and-password' ) . click ( onSignInWithEmailAndPassword ) ;
1900
+ $ ( '#reauth-with-email-and-password' ) . click (
1901
+ onReauthenticateWithEmailAndPassword
1902
+ ) ;
1863
1903
$ ( '.sign-in-with-custom-token' ) . click ( onSignInWithCustomToken ) ;
1864
1904
$ ( '#sign-in-anonymously' ) . click ( onSignInAnonymously ) ;
1865
1905
$ ( '#sign-in-with-generic-idp-credential' ) . click (
0 commit comments