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

Function toggleSignIn

auth/facebook-popup.ts:36–71  ·  view source on GitHub ↗

* Function called when clicking the Login/Logout button.

()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected