MCPcopy Create free account
hub / github.com/firebase/quickstart-js / toggleSignIn

Function toggleSignIn

auth/twitter-popup.ts:39–76  ·  view source on GitHub ↗

* Function called when clicking the Login/Logout button.

()

Source from the content-addressed store, hash-verified

37 * Function called when clicking the Login/Logout button.
38 */
39function toggleSignIn() {
40 if (!auth.currentUser) {
41 const provider = new TwitterAuthProvider();
42 signInWithPopup(auth, provider)
43 .then(function (result) {
44 const credential = TwitterAuthProvider.credentialFromResult(result);
45 // This gives you a the Twitter OAuth 1.0 Access Token and Secret.
46 // You can use these server side with your app's credentials to access the Twitter API.
47 const token = credential?.accessToken;
48 const secret = credential?.secret;
49 // The signed-in user info.
50 const user = result.user;
51 oauthtoken.textContent = token ?? '';
52 oauthsecret.textContent = secret ?? '';
53 })
54 .catch(function (error) {
55 // Handle Errors here.
56 const errorCode = error.code;
57 const errorMessage = error.message;
58 // The email of the user's account used.
59 const email = error.email;
60 // The firebase.auth.AuthCredential type that was used.
61 const credential = error.credential;
62 if (errorCode === 'auth/account-exists-with-different-credential') {
63 alert(
64 'You have already signed up with a different auth provider for that email.',
65 );
66 // If you are using multiple auth providers on your app you should handle linking
67 // the user's accounts here.
68 } else {
69 console.error(error);
70 }
71 });
72 } else {
73 signOut(auth);
74 }
75 signInButton.disabled = true;
76}
77
78// Listening for auth state changes.
79onAuthStateChanged(auth, function (user) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected