@@ -247,6 +247,7 @@ 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
+ setLastUser ( activeUser ) ;
250
251
mfaUser . unenroll ( info ) . then ( ( ) => {
251
252
refreshUserData ( ) ;
252
253
alertSuccess ( 'Multi-factor successfully unenrolled.' ) ;
@@ -278,6 +279,10 @@ function onAuthError(error) {
278
279
handleMultiFactorSignIn ( getMultiFactorResolver ( auth , error ) ) ;
279
280
} else {
280
281
alertError ( 'Error: ' + error . code ) ;
282
+ if ( error . code === 'auth/user-token-expired' ) {
283
+ console . log ( lastUser ) ;
284
+ alertError ( "Token expired, please reauthenticate." ) ;
285
+ }
281
286
}
282
287
}
283
288
@@ -403,13 +408,37 @@ function onLinkWithEmailLink() {
403
408
* Re-authenticate a user with email link credential.
404
409
*/
405
410
function onReauthenticateWithEmailLink ( ) {
411
+ if ( ! activeUser ( ) ) {
412
+ alertError ( 'No user logged in. Select the "Last User" tab to reauth the previous user.' ) ;
413
+ return ;
414
+ }
406
415
const email = $ ( '#link-with-email-link-email' ) . val ( ) ;
407
416
const link = $ ( '#link-with-email-link-link' ) . val ( ) || undefined ;
408
417
const credential = EmailAuthProvider . credentialWithLink ( email , link ) ;
418
+ // This will not set auth.currentUser to lastUser if the lastUser is reauthenticated.
409
419
reauthenticateWithCredential ( activeUser ( ) , credential ) . then ( result => {
410
420
logAdditionalUserInfo ( result ) ;
411
421
refreshUserData ( ) ;
412
- alertSuccess ( 'User reauthenticated!' ) ;
422
+ alertSuccess ( 'User reauthenticated with email link!' ) ;
423
+ } , onAuthError ) ;
424
+ }
425
+
426
+ /**
427
+ * Re-authenticate a user with email and password.
428
+ */
429
+ function onReauthenticateWithEmailAndPassword ( ) {
430
+ if ( ! activeUser ( ) ) {
431
+ alertError ( 'No user logged in. Select the "Last User" tab to reauth the previous user.' ) ;
432
+ return ;
433
+ }
434
+ const email = $ ( '#signin-email' ) . val ( ) ;
435
+ const password = $ ( '#signin-password' ) . val ( ) ;
436
+ const credential = EmailAuthProvider . credential ( email , password ) ;
437
+ // This will not set auth.currentUser to lastUser if the lastUser is reauthenticated.
438
+ reauthenticateWithCredential ( activeUser ( ) , credential ) . then ( result => {
439
+ logAdditionalUserInfo ( result ) ;
440
+ refreshUserData ( ) ;
441
+ alertSuccess ( 'User reauthenticated with email/password!' ) ;
413
442
} , onAuthError ) ;
414
443
}
415
444
@@ -1264,7 +1293,7 @@ function signInWithPopupRedirect(provider) {
1264
1293
break ;
1265
1294
case 'reauthenticate' :
1266
1295
if ( ! activeUser ( ) ) {
1267
- alertError ( 'No user logged in.' ) ;
1296
+ alertError ( 'No user logged in. Select the "Last User" tab to reauth the previous user. ' ) ;
1268
1297
return ;
1269
1298
}
1270
1299
inst = activeUser ( ) ;
@@ -1860,6 +1889,7 @@ function initApp() {
1860
1889
// Actions listeners.
1861
1890
$ ( '#sign-up-with-email-and-password' ) . click ( onSignUp ) ;
1862
1891
$ ( '#sign-in-with-email-and-password' ) . click ( onSignInWithEmailAndPassword ) ;
1892
+ $ ( '#reauth-with-email-and-password' ) . click ( onReauthenticateWithEmailAndPassword ) ;
1863
1893
$ ( '.sign-in-with-custom-token' ) . click ( onSignInWithCustomToken ) ;
1864
1894
$ ( '#sign-in-anonymously' ) . click ( onSignInAnonymously ) ;
1865
1895
$ ( '#sign-in-with-generic-idp-credential' ) . click (
0 commit comments