@@ -35,7 +35,15 @@ import {
35
35
signInAnonymously ,
36
36
signInWithCustomToken ,
37
37
isSignInWithEmailLink ,
38
- fetchSignInMethodsForEmail
38
+ fetchSignInMethodsForEmail ,
39
+ createUserWithEmailAndPassword ,
40
+ signInWithEmailAndPassword ,
41
+ sendSignInLinkToEmail ,
42
+ sendPasswordResetEmail ,
43
+ verifyPasswordResetCode ,
44
+ confirmPasswordReset ,
45
+ linkWithCredential ,
46
+ unlink
39
47
} from '@firebase/auth-exp' ;
40
48
41
49
import { config } from './config' ;
@@ -312,22 +320,20 @@ function onSetPersistence() {
312
320
* Signs up a new user with an email and a password.
313
321
*/
314
322
function onSignUp ( ) {
315
- alertNotImplemented ( ) ;
316
- // var email = $('#signup-email').val();
317
- // var password = $('#signup-password').val();
318
- // auth.createUserWithEmailAndPassword(email, password)
319
- // .then(onAuthUserCredentialSuccess, onAuthError);
323
+ var email = $ ( '#signup-email' ) . val ( ) ;
324
+ var password = $ ( '#signup-password' ) . val ( ) ;
325
+ createUserWithEmailAndPassword ( auth , email , password )
326
+ . then ( onAuthUserCredentialSuccess , onAuthError ) ;
320
327
}
321
328
322
329
/**
323
330
* Signs in a user with an email and a password.
324
331
*/
325
332
function onSignInWithEmailAndPassword ( ) {
326
- alertNotImplemented ( ) ;
327
- // var email = $('#signin-email').val();
328
- // var password = $('#signin-password').val();
329
- // signInWithEmailAndPassword(auth, email, password)
330
- // .then(onAuthUserCredentialSuccess, onAuthError);
333
+ var email = $ ( '#signin-email' ) . val ( ) ;
334
+ var password = $ ( '#signin-password' ) . val ( ) ;
335
+ signInWithEmailAndPassword ( auth , email , password )
336
+ . then ( onAuthUserCredentialSuccess , onAuthError ) ;
331
337
}
332
338
333
339
/**
@@ -347,13 +353,12 @@ function onSignInWithEmailLink() {
347
353
* Links a user with an email link.
348
354
*/
349
355
function onLinkWithEmailLink ( ) {
350
- alertNotImplemented ( ) ;
351
- // var email = $('#link-with-email-link-email').val();
352
- // var link = $('#link-with-email-link-link').val() || undefined;
353
- // var credential = firebase.auth.EmailAuthProvider
354
- // .credentialWithLink(email, link);
355
- // activeUser().linkWithCredential(credential)
356
- // .then(onAuthUserCredentialSuccess, onAuthError);
356
+ var email = $ ( '#link-with-email-link-email' ) . val ( ) ;
357
+ var link = $ ( '#link-with-email-link-link' ) . val ( ) || undefined ;
358
+ var credential = firebase . auth . EmailAuthProvider
359
+ . credentialWithLink ( email , link ) ;
360
+ linkWithCredential ( activeUser ( ) , credential )
361
+ . then ( onAuthUserCredentialSuccess , onAuthError ) ;
357
362
}
358
363
359
364
/**
@@ -623,8 +628,8 @@ function signInOrLinkCredential(credential) {
623
628
alertError ( 'You need to sign in before linking an account.' ) ;
624
629
return ;
625
630
}
626
- activeUser ( )
627
- . linkWithCredential ( credential )
631
+
632
+ linkWithCredential ( activeUser ( ) , credential )
628
633
. then ( function ( result ) {
629
634
logAdditionalUserInfo ( result ) ;
630
635
refreshUserData ( ) ;
@@ -715,81 +720,75 @@ function onUpdateProfile() {
715
720
* Sends sign in with email link to the user.
716
721
*/
717
722
function onSendSignInLinkToEmail ( ) {
718
- alertNotImplemented ( ) ;
719
- // var email = $('#sign-in-with-email-link-email').val();
720
- // auth.sendSignInLinkToEmail(email, getActionCodeSettings()).then(function() {
721
- // alertSuccess('Email sent!');
722
- // }, onAuthError);
723
+ var email = $ ( '#sign-in-with-email-link-email' ) . val ( ) ;
724
+ sendSignInLinkToEmail ( auth , email , getActionCodeSettings ( ) ) . then ( function ( ) {
725
+ alertSuccess ( 'Email sent!' ) ;
726
+ } , onAuthError ) ;
723
727
}
724
728
725
729
/**
726
730
* Sends sign in with email link to the user and pass in current url.
727
731
*/
728
732
function onSendSignInLinkToEmailCurrentUrl ( ) {
729
- alertNotImplemented ( ) ;
730
- // var email = $('#sign-in-with-email-link-email').val();
731
- // var actionCodeSettings = {
732
- // 'url': window.location.href,
733
- // 'handleCodeInApp': true
734
- // };
733
+ var email = $ ( '#sign-in-with-email-link-email' ) . val ( ) ;
734
+ var actionCodeSettings = {
735
+ 'url' : window . location . href ,
736
+ 'handleCodeInApp' : true
737
+ } ;
735
738
736
- // auth. sendSignInLinkToEmail(email, actionCodeSettings).then(function() {
737
- // if ('localStorage' in window && window['localStorage'] !== null) {
738
- // window.localStorage.setItem(
739
- // 'emailForSignIn',
740
- // // Save the email and the timestamp.
741
- // JSON.stringify({
742
- // email: email,
743
- // timestamp: new Date().getTime()
744
- // }));
745
- // }
746
- // alertSuccess('Email sent!');
747
- // }, onAuthError);
739
+ sendSignInLinkToEmail ( auth , email , actionCodeSettings ) . then ( function ( ) {
740
+ if ( 'localStorage' in window && window [ 'localStorage' ] !== null ) {
741
+ window . localStorage . setItem (
742
+ 'emailForSignIn' ,
743
+ // Save the email and the timestamp.
744
+ JSON . stringify ( {
745
+ email : email ,
746
+ timestamp : new Date ( ) . getTime ( )
747
+ } ) ) ;
748
+ }
749
+ alertSuccess ( 'Email sent!' ) ;
750
+ } , onAuthError ) ;
748
751
}
749
752
750
753
/**
751
754
* Sends email link to link the user.
752
755
*/
753
756
function onSendLinkEmailLink ( ) {
754
- alertNotImplemented ( ) ;
755
- // var email = $('#link-with-email-link-email').val();
756
- // auth.sendSignInLinkToEmail(email, getActionCodeSettings()).then(function() {
757
- // alertSuccess('Email sent!');
758
- // }, onAuthError);
757
+ var email = $ ( '#link-with-email-link-email' ) . val ( ) ;
758
+ sendSignInLinkToEmail ( auth , email , getActionCodeSettings ( ) ) . then ( function ( ) {
759
+ alertSuccess ( 'Email sent!' ) ;
760
+ } , onAuthError ) ;
759
761
}
760
762
761
763
/**
762
764
* Sends password reset email to the user.
763
765
*/
764
766
function onSendPasswordResetEmail ( ) {
765
- alertNotImplemented ( ) ;
766
- // var email = $('#password-reset-email').val();
767
- // auth.sendPasswordResetEmail(email, getActionCodeSettings()).then(function() {
768
- // alertSuccess('Email sent!');
769
- // }, onAuthError);
767
+ var email = $ ( '#password-reset-email' ) . val ( ) ;
768
+ sendPasswordResetEmail ( auth , email , getActionCodeSettings ( ) ) . then ( function ( ) {
769
+ alertSuccess ( 'Email sent!' ) ;
770
+ } , onAuthError ) ;
770
771
}
771
772
772
773
/**
773
774
* Verifies the password reset code entered by the user.
774
775
*/
775
776
function onVerifyPasswordResetCode ( ) {
776
- alertNotImplemented ( ) ;
777
- // var code = $('#password-reset-code').val();
778
- // auth.verifyPasswordResetCode(code).then(function() {
779
- // alertSuccess('Password reset code is valid!');
780
- // }, onAuthError);
777
+ var code = $ ( '#password-reset-code' ) . val ( ) ;
778
+ verifyPasswordResetCode ( auth , code ) . then ( function ( ) {
779
+ alertSuccess ( 'Password reset code is valid!' ) ;
780
+ } , onAuthError ) ;
781
781
}
782
782
783
783
/**
784
784
* Confirms the password reset with the code and password supplied by the user.
785
785
*/
786
786
function onConfirmPasswordReset ( ) {
787
- alertNotImplemented ( ) ;
788
- // var code = $('#password-reset-code').val();
789
- // var password = $('#password-reset-password').val();
790
- // auth.confirmPasswordReset(code, password).then(function() {
791
- // alertSuccess('Password has been changed!');
792
- // }, onAuthError);
787
+ var code = $ ( '#password-reset-code' ) . val ( ) ;
788
+ var password = $ ( '#password-reset-password' ) . val ( ) ;
789
+ confirmPasswordReset ( auth , code , password ) . then ( function ( ) {
790
+ alertSuccess ( 'Password has been changed!' ) ;
791
+ } , onAuthError ) ;
793
792
}
794
793
795
794
/**
@@ -822,12 +821,12 @@ function onGetProviderData() {
822
821
* Links a signed in user with an email and password account.
823
822
*/
824
823
function onLinkWithEmailAndPassword ( ) {
825
- alertNotImplemented ( ) ;
826
- // var email = $('#link-email ').val();
827
- // var password = $('#link-password').val();
828
- // activeUser().linkWithCredential(
829
- // firebase.auth.EmailAuthProvider.credential(email, password))
830
- // .then(onAuthUserCredentialSuccess, onAuthError);
824
+ var email = $ ( '#link-email' ) . val ( ) ;
825
+ var password = $ ( '#link-password ' ) . val ( ) ;
826
+ linkWithCredential (
827
+ activeUser ( ) ,
828
+ firebase . auth . EmailAuthProvider . credential ( email , password ) )
829
+ . then ( onAuthUserCredentialSuccess , onAuthError ) ;
831
830
}
832
831
833
832
/**
@@ -853,8 +852,7 @@ function onLinkWithGenericIdPCredential() {
853
852
*/
854
853
function onUnlinkProvider ( ) {
855
854
var providerId = $ ( '#unlinked-provider-id' ) . val ( ) ;
856
- activeUser ( )
857
- . unlink ( providerId )
855
+ unlink ( activeUser ( ) , providerId )
858
856
. then ( function ( user ) {
859
857
alertSuccess ( 'Provider unlinked from user.' ) ;
860
858
refreshUserData ( ) ;
0 commit comments