Skip to content

Commit 3e10ec8

Browse files
authored
Remove auth snippets, move to snippets-web (#502)
1 parent 178470c commit 3e10ec8

19 files changed

+2
-241
lines changed

auth/anon.html

-14
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,18 @@
4141
*/
4242
function toggleSignIn() {
4343
if (firebase.auth().currentUser) {
44-
// [START signout]
4544
firebase.auth().signOut();
46-
// [END signout]
4745
} else {
48-
// [START authanon]
4946
firebase.auth().signInAnonymously().catch(function(error) {
5047
// Handle Errors here.
5148
var errorCode = error.code;
5249
var errorMessage = error.message;
53-
// [START_EXCLUDE]
5450
if (errorCode === 'auth/operation-not-allowed') {
5551
alert('You must enable Anonymous auth in the Firebase Console.');
5652
} else {
5753
console.error(error);
5854
}
59-
// [END_EXCLUDE]
6055
});
61-
// [END authanon]
6256
}
6357
document.getElementById('quickstart-sign-in').disabled = true;
6458
}
@@ -71,30 +65,22 @@
7165
*/
7266
function initApp() {
7367
// Listening for auth state changes.
74-
// [START authstatelistener]
7568
firebase.auth().onAuthStateChanged(function(user) {
7669
if (user) {
7770
// User is signed in.
7871
var isAnonymous = user.isAnonymous;
7972
var uid = user.uid;
80-
// [START_EXCLUDE]
8173
document.getElementById('quickstart-sign-in-status').textContent = 'Signed in';
8274
document.getElementById('quickstart-sign-in').textContent = 'Sign out';
8375
document.getElementById('quickstart-account-details').textContent = JSON.stringify(user, null, ' ');
84-
// [END_EXCLUDE]
8576
} else {
8677
// User is signed out.
87-
// [START_EXCLUDE]
8878
document.getElementById('quickstart-sign-in-status').textContent = 'Signed out';
8979
document.getElementById('quickstart-sign-in').textContent = 'Sign in';
9080
document.getElementById('quickstart-account-details').textContent = 'null';
91-
// [END_EXCLUDE]
9281
}
93-
// [START_EXCLUDE]
9482
document.getElementById('quickstart-sign-in').disabled = false;
95-
// [END_EXCLUDE]
9683
});
97-
// [END authstatelistener]
9884

9985
document.getElementById('quickstart-sign-in').addEventListener('click', toggleSignIn, false);
10086
}

auth/apple-popup.html

-10
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@
9898
});
9999
// [END signin]
100100
} else {
101-
// [START signout]
102101
firebase.auth().signOut();
103-
// [END signout]
104102
}
105103
// [START_EXCLUDE]
106104
document.getElementById('quickstart-sign-in').disabled = true;
@@ -115,7 +113,6 @@
115113
*/
116114
function initApp() {
117115
// Listening for auth state changes.
118-
// [START authstatelistener]
119116
firebase.auth().onAuthStateChanged(function(user) {
120117
if (user) {
121118
// User is signed in. Note that unlike other providers supported by Firebase Auth, Apple does
@@ -126,18 +123,15 @@
126123
var isAnonymous = user.isAnonymous;
127124
var uid = user.uid;
128125
var providerData = user.providerData;
129-
// [START_EXCLUDE]
130126
document.getElementById('quickstart-sign-in-status').textContent =
131127
'Signed in';
132128
document.getElementById('quickstart-sign-in').textContent =
133129
'Log out';
134130
document.getElementById(
135131
'quickstart-account-details'
136132
).textContent = JSON.stringify(user, null, ' ');
137-
// [END_EXCLUDE]
138133
} else {
139134
// User is signed out.
140-
// [START_EXCLUDE]
141135
document.getElementById('quickstart-sign-in-status').textContent =
142136
'Signed out';
143137
document.getElementById('quickstart-sign-in').textContent =
@@ -146,13 +140,9 @@
146140
'null';
147141
document.getElementById('quickstart-oauthtoken').textContent =
148142
'null';
149-
// [END_EXCLUDE]
150143
}
151-
// [START_EXCLUDE]
152144
document.getElementById('quickstart-sign-in').disabled = false;
153-
// [END_EXCLUDE]
154145
});
155-
// [END authstatelistener]
156146

157147
document
158148
.getElementById('quickstart-sign-in')

auth/apple-redirect.html

-10
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@
5858
firebase.auth().signInWithRedirect(provider);
5959
// [END signin]
6060
} else {
61-
// [START signout]
6261
firebase.auth().signOut();
63-
// [END signout]
6462
}
6563
// [START_EXCLUDE]
6664
document.getElementById('quickstart-sign-in').disabled = true;
@@ -122,7 +120,6 @@
122120
// [END getidptoken]
123121

124122
// Listening for auth state changes.
125-
// [START authstatelistener]
126123
firebase.auth().onAuthStateChanged(function(user) {
127124
if (user) {
128125
// User is signed in. Note that unlike other providers supported by Firebase Auth, Apple does
@@ -133,18 +130,15 @@
133130
var isAnonymous = user.isAnonymous;
134131
var uid = user.uid;
135132
var providerData = user.providerData;
136-
// [START_EXCLUDE]
137133
document.getElementById('quickstart-sign-in-status').textContent =
138134
'Signed in';
139135
document.getElementById('quickstart-sign-in').textContent =
140136
'Log out';
141137
document.getElementById(
142138
'quickstart-account-details'
143139
).textContent = JSON.stringify(user, null, ' ');
144-
// [END_EXCLUDE]
145140
} else {
146141
// User is signed out.
147-
// [START_EXCLUDE]
148142
document.getElementById('quickstart-sign-in-status').textContent =
149143
'Signed out';
150144
document.getElementById('quickstart-sign-in').textContent =
@@ -153,13 +147,9 @@
153147
'null';
154148
document.getElementById('quickstart-oauthtoken').textContent =
155149
'null';
156-
// [END_EXCLUDE]
157150
}
158-
// [START_EXCLUDE]
159151
document.getElementById('quickstart-sign-in').disabled = false;
160-
// [END_EXCLUDE]
161152
});
162-
// [END authstatelistener]
163153

164154
document
165155
.getElementById('quickstart-sign-in')

auth/chromextension/credentials.js

-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ firebase.initializeApp(config);
2323
*/
2424
function initApp() {
2525
// Listen for auth state changes.
26-
// [START authstatelistener]
2726
firebase.auth().onAuthStateChanged(function(user) {
2827
if (user) {
2928
// User is signed in.
@@ -34,22 +33,17 @@ function initApp() {
3433
var isAnonymous = user.isAnonymous;
3534
var uid = user.uid;
3635
var providerData = user.providerData;
37-
// [START_EXCLUDE]
3836
document.getElementById('quickstart-button').textContent = 'Sign out';
3937
document.getElementById('quickstart-sign-in-status').textContent = 'Signed in';
4038
document.getElementById('quickstart-account-details').textContent = JSON.stringify(user, null, ' ');
41-
// [END_EXCLUDE]
4239
} else {
4340
// Let's try to get a Google auth token programmatically.
44-
// [START_EXCLUDE]
4541
document.getElementById('quickstart-button').textContent = 'Sign-in with Google';
4642
document.getElementById('quickstart-sign-in-status').textContent = 'Signed out';
4743
document.getElementById('quickstart-account-details').textContent = 'null';
48-
// [END_EXCLUDE]
4944
}
5045
document.getElementById('quickstart-button').disabled = false;
5146
});
52-
// [END authstatelistener]
5347

5448
document.getElementById('quickstart-button').addEventListener('click', startSignIn, false);
5549
}

auth/customauth.html

-14
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,24 @@
4141
*/
4242
function toggleSignIn() {
4343
if (firebase.auth().currentUser) {
44-
// [START signout]
4544
firebase.auth().signOut();
46-
// [END signout]
4745
} else {
4846
var token = document.getElementById('tokentext').value;
4947
if (token.length < 10) {
5048
alert('Please enter a token in the text area');
5149
return;
5250
}
5351
// Sign in with custom token generated following previous instructions.
54-
// [START authwithtoken]
5552
firebase.auth().signInWithCustomToken(token).catch(function(error) {
5653
// Handle Errors here.
5754
var errorCode = error.code;
5855
var errorMessage = error.message;
59-
// [START_EXCLUDE]
6056
if (errorCode === 'auth/invalid-custom-token') {
6157
alert('The token you provided is not valid.');
6258
} else {
6359
console.error(error);
6460
}
65-
// [END_EXCLUDE]
6661
});
67-
// [END authwithtoken]
6862
}
6963
document.getElementById('quickstart-sign-in').disabled = true;
7064
}
@@ -77,7 +71,6 @@
7771
*/
7872
function initApp() {
7973
// Listening for auth state changes.
80-
// [START authstatelistener]
8174
firebase.auth().onAuthStateChanged(function(user) {
8275
if (user) {
8376
// User is signed in.
@@ -88,24 +81,17 @@
8881
var isAnonymous = user.isAnonymous;
8982
var uid = user.uid;
9083
var providerData = user.providerData;
91-
// [START_EXCLUDE]
9284
document.getElementById('quickstart-sign-in-status').textContent = 'Signed in';
9385
document.getElementById('quickstart-sign-in').textContent = 'Sign out';
9486
document.getElementById('quickstart-account-details').textContent = JSON.stringify(user, null, ' ');
95-
// [END_EXCLUDE]
9687
} else {
9788
// User is signed out.
98-
// [START_EXCLUDE]
9989
document.getElementById('quickstart-sign-in-status').textContent = 'Signed out';
10090
document.getElementById('quickstart-sign-in').textContent = 'Sign in';
10191
document.getElementById('quickstart-account-details').textContent = 'null';
102-
// [END_EXCLUDE]
10392
}
104-
// [START_EXCLUDE]
10593
document.getElementById('quickstart-sign-in').disabled = false;
106-
// [END_EXCLUDE]
10794
});
108-
// [END authstatelistener]
10995

11096
document.getElementById('quickstart-sign-in').addEventListener('click', toggleSignIn, false);
11197
}

auth/email-link.html

-24
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,15 @@
4444
document.getElementById('quickstart-sign-in').disabled = true;
4545

4646
if (firebase.auth().currentUser) {
47-
// [START signout]
4847
firebase.auth().signOut().catch(function(error) {
4948
// Handle Errors here.
5049
var errorCode = error.code;
5150
var errorMessage = error.message;
52-
// [START_EXCLUDE]
5351
handleError(error);
54-
// [END_EXCLUDE]
5552
});
56-
// [END signout]
5753
} else {
5854
var email = document.getElementById('email').value;
5955
// Sending email with sign-in link.
60-
// [START authwithemail]
6156
var actionCodeSettings = {
6257
// URL you want to redirect back to. The domain (www.example.com) for this URL
6358
// must be whitelisted in the Firebase Console.
@@ -71,19 +66,14 @@
7166
window.localStorage.setItem('emailForSignIn', email);
7267
// The link was successfully sent. Inform the user.
7368
alert('An email was sent to ' + email + '. Please use the link in the email to sign-in.');
74-
// [START_EXCLUDE]
7569
// Re-enable the sign-in button.
7670
document.getElementById('quickstart-sign-in').disabled = false;
77-
// [END_EXCLUDE]
7871
}).catch(function(error) {
7972
// Handle Errors here.
8073
var errorCode = error.code;
8174
var errorMessage = error.message;
82-
// [START_EXCLUDE]
8375
handleError(error);
84-
// [END_EXCLUDE]
8576
});
86-
// [END authwithemail]
8777
}
8878
}
8979

@@ -102,12 +92,9 @@
10292
* Handles automatically signing-in the app if we clicked on the sign-in link in the email.
10393
*/
10494
function handleSignIn() {
105-
// [START handlesignin]
10695
if (firebase.auth().isSignInWithEmailLink(window.location.href)) {
107-
// [START_EXCLUDE]
10896
// Disable the sign-in button during async sign-in tasks.
10997
document.getElementById('quickstart-sign-in').disabled = true;
110-
// [END_EXCLUDE]
11198

11299
// You can also get the other parameters passed in the query string such as state=STATE.
113100
// Get the email if available.
@@ -134,13 +121,10 @@
134121
// Handle Errors here.
135122
var errorCode = error.code;
136123
var errorMessage = error.message;
137-
// [START_EXCLUDE]
138124
handleError(error);
139-
// [END_EXCLUDE]
140125
});
141126
}
142127
}
143-
// [END handlesignin]
144128
}
145129

146130
/**
@@ -157,7 +141,6 @@
157141
handleSignIn();
158142

159143
// Listening for auth state changes.
160-
// [START authstatelistener]
161144
firebase.auth().onAuthStateChanged(function(user) {
162145
if (user) {
163146
// User is signed in.
@@ -169,25 +152,18 @@
169152
var uid = user.uid;
170153
var providerData = user.providerData;
171154
// Update UI.
172-
// [START_EXCLUDE]
173155
document.getElementById('quickstart-sign-in-status').textContent = 'Signed in';
174156
document.getElementById('quickstart-sign-in').textContent = 'Sign out';
175157
document.getElementById('quickstart-account-details').textContent = JSON.stringify(user, null, ' ');
176-
// [END_EXCLUDE]
177158
} else {
178159
// User is signed out.
179160
// Update UI.
180-
// [START_EXCLUDE]
181161
document.getElementById('quickstart-sign-in-status').textContent = 'Signed out';
182162
document.getElementById('quickstart-sign-in').textContent = 'Sign In without password';
183163
document.getElementById('quickstart-account-details').textContent = 'null';
184-
// [END_EXCLUDE]
185164
}
186-
// [START_EXCLUDE silent]
187165
document.getElementById('quickstart-sign-in').disabled = false;
188-
// [END_EXCLUDE]
189166
});
190-
// [END authstatelistener]
191167

192168
document.getElementById('quickstart-sign-in').addEventListener('click', toggleSignIn, false);
193169
}

0 commit comments

Comments
 (0)