Skip to content

Commit ee8d92c

Browse files
committed
Update to include newly-implemented pieces
1 parent 728db4d commit ee8d92c

File tree

2 files changed

+73
-73
lines changed

2 files changed

+73
-73
lines changed

packages-exp/auth-exp/demo/src/index.js

Lines changed: 70 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ import {
3535
signInAnonymously,
3636
signInWithCustomToken,
3737
isSignInWithEmailLink,
38-
fetchSignInMethodsForEmail
38+
fetchSignInMethodsForEmail,
39+
createUserWithEmailAndPassword,
40+
signInWithEmailAndPassword,
41+
sendSignInLinkToEmail,
42+
sendPasswordResetEmail,
43+
verifyPasswordResetCode,
44+
confirmPasswordReset,
45+
linkWithCredential,
46+
unlink
3947
} from '@firebase/auth-exp';
4048

4149
import { config } from './config';
@@ -312,22 +320,20 @@ function onSetPersistence() {
312320
* Signs up a new user with an email and a password.
313321
*/
314322
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);
320327
}
321328

322329
/**
323330
* Signs in a user with an email and a password.
324331
*/
325332
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);
331337
}
332338

333339
/**
@@ -347,13 +353,12 @@ function onSignInWithEmailLink() {
347353
* Links a user with an email link.
348354
*/
349355
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);
357362
}
358363

359364
/**
@@ -623,8 +628,8 @@ function signInOrLinkCredential(credential) {
623628
alertError('You need to sign in before linking an account.');
624629
return;
625630
}
626-
activeUser()
627-
.linkWithCredential(credential)
631+
632+
linkWithCredential(activeUser(), credential)
628633
.then(function(result) {
629634
logAdditionalUserInfo(result);
630635
refreshUserData();
@@ -715,81 +720,75 @@ function onUpdateProfile() {
715720
* Sends sign in with email link to the user.
716721
*/
717722
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);
723727
}
724728

725729
/**
726730
* Sends sign in with email link to the user and pass in current url.
727731
*/
728732
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+
};
735738

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);
748751
}
749752

750753
/**
751754
* Sends email link to link the user.
752755
*/
753756
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);
759761
}
760762

761763
/**
762764
* Sends password reset email to the user.
763765
*/
764766
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);
770771
}
771772

772773
/**
773774
* Verifies the password reset code entered by the user.
774775
*/
775776
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);
781781
}
782782

783783
/**
784784
* Confirms the password reset with the code and password supplied by the user.
785785
*/
786786
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);
793792
}
794793

795794
/**
@@ -822,12 +821,12 @@ function onGetProviderData() {
822821
* Links a signed in user with an email and password account.
823822
*/
824823
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);
831830
}
832831

833832
/**
@@ -853,8 +852,7 @@ function onLinkWithGenericIdPCredential() {
853852
*/
854853
function onUnlinkProvider() {
855854
var providerId = $('#unlinked-provider-id').val();
856-
activeUser()
857-
.unlink(providerId)
855+
unlink(activeUser(), providerId)
858856
.then(function(user) {
859857
alertSuccess('Provider unlinked from user.');
860858
refreshUserData();

packages-exp/auth-exp/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import * as externs from '@firebase/auth-types-exp';
19-
import { ErrorFn, CompleteFn, Unsubscribe } from '@firebase/util';
19+
import { CompleteFn, ErrorFn, Unsubscribe } from '@firebase/util';
2020

2121
// core/auth
2222
export { initializeAuth } from './core/auth/auth_impl';
@@ -101,6 +101,8 @@ export {
101101
export { getIdToken, getIdTokenResult } from './core/user/id_token_result';
102102
export { unlink } from './core/user/unlink';
103103

104+
export { RecaptchaVerifier } from './platform_browser/recaptcha/recaptcha_verifier';
105+
104106
// Non-optional user methods.
105107
export { reload } from './core/user/reload';
106108
export async function deleteUser(user: externs.User): Promise<void> {

0 commit comments

Comments
 (0)