|
44 | 44 | document.getElementById('quickstart-sign-in').disabled = true;
|
45 | 45 |
|
46 | 46 | if (firebase.auth().currentUser) {
|
47 |
| - // [START signout] |
48 | 47 | firebase.auth().signOut().catch(function(error) {
|
49 | 48 | // Handle Errors here.
|
50 | 49 | var errorCode = error.code;
|
51 | 50 | var errorMessage = error.message;
|
52 |
| - // [START_EXCLUDE] |
53 | 51 | handleError(error);
|
54 |
| - // [END_EXCLUDE] |
55 | 52 | });
|
56 |
| - // [END signout] |
57 | 53 | } else {
|
58 | 54 | var email = document.getElementById('email').value;
|
59 | 55 | // Sending email with sign-in link.
|
60 |
| - // [START authwithemail] |
61 | 56 | var actionCodeSettings = {
|
62 | 57 | // URL you want to redirect back to. The domain (www.example.com) for this URL
|
63 | 58 | // must be whitelisted in the Firebase Console.
|
|
71 | 66 | window.localStorage.setItem('emailForSignIn', email);
|
72 | 67 | // The link was successfully sent. Inform the user.
|
73 | 68 | alert('An email was sent to ' + email + '. Please use the link in the email to sign-in.');
|
74 |
| - // [START_EXCLUDE] |
75 | 69 | // Re-enable the sign-in button.
|
76 | 70 | document.getElementById('quickstart-sign-in').disabled = false;
|
77 |
| - // [END_EXCLUDE] |
78 | 71 | }).catch(function(error) {
|
79 | 72 | // Handle Errors here.
|
80 | 73 | var errorCode = error.code;
|
81 | 74 | var errorMessage = error.message;
|
82 |
| - // [START_EXCLUDE] |
83 | 75 | handleError(error);
|
84 |
| - // [END_EXCLUDE] |
85 | 76 | });
|
86 |
| - // [END authwithemail] |
87 | 77 | }
|
88 | 78 | }
|
89 | 79 |
|
|
102 | 92 | * Handles automatically signing-in the app if we clicked on the sign-in link in the email.
|
103 | 93 | */
|
104 | 94 | function handleSignIn() {
|
105 |
| - // [START handlesignin] |
106 | 95 | if (firebase.auth().isSignInWithEmailLink(window.location.href)) {
|
107 |
| - // [START_EXCLUDE] |
108 | 96 | // Disable the sign-in button during async sign-in tasks.
|
109 | 97 | document.getElementById('quickstart-sign-in').disabled = true;
|
110 |
| - // [END_EXCLUDE] |
111 | 98 |
|
112 | 99 | // You can also get the other parameters passed in the query string such as state=STATE.
|
113 | 100 | // Get the email if available.
|
|
134 | 121 | // Handle Errors here.
|
135 | 122 | var errorCode = error.code;
|
136 | 123 | var errorMessage = error.message;
|
137 |
| - // [START_EXCLUDE] |
138 | 124 | handleError(error);
|
139 |
| - // [END_EXCLUDE] |
140 | 125 | });
|
141 | 126 | }
|
142 | 127 | }
|
143 |
| - // [END handlesignin] |
144 | 128 | }
|
145 | 129 |
|
146 | 130 | /**
|
|
157 | 141 | handleSignIn();
|
158 | 142 |
|
159 | 143 | // Listening for auth state changes.
|
160 |
| - // [START authstatelistener] |
161 | 144 | firebase.auth().onAuthStateChanged(function(user) {
|
162 | 145 | if (user) {
|
163 | 146 | // User is signed in.
|
|
169 | 152 | var uid = user.uid;
|
170 | 153 | var providerData = user.providerData;
|
171 | 154 | // Update UI.
|
172 |
| - // [START_EXCLUDE] |
173 | 155 | document.getElementById('quickstart-sign-in-status').textContent = 'Signed in';
|
174 | 156 | document.getElementById('quickstart-sign-in').textContent = 'Sign out';
|
175 | 157 | document.getElementById('quickstart-account-details').textContent = JSON.stringify(user, null, ' ');
|
176 |
| - // [END_EXCLUDE] |
177 | 158 | } else {
|
178 | 159 | // User is signed out.
|
179 | 160 | // Update UI.
|
180 |
| - // [START_EXCLUDE] |
181 | 161 | document.getElementById('quickstart-sign-in-status').textContent = 'Signed out';
|
182 | 162 | document.getElementById('quickstart-sign-in').textContent = 'Sign In without password';
|
183 | 163 | document.getElementById('quickstart-account-details').textContent = 'null';
|
184 |
| - // [END_EXCLUDE] |
185 | 164 | }
|
186 |
| - // [START_EXCLUDE silent] |
187 | 165 | document.getElementById('quickstart-sign-in').disabled = false;
|
188 |
| - // [END_EXCLUDE] |
189 | 166 | });
|
190 |
| - // [END authstatelistener] |
191 | 167 |
|
192 | 168 | document.getElementById('quickstart-sign-in').addEventListener('click', toggleSignIn, false);
|
193 | 169 | }
|
|
0 commit comments