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

Function toggleSignIn

auth/google-popup.ts:36–72  ·  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 GoogleAuthProvider();
39 provider.addScope('https://www.googleapis.com/auth/contacts.readonly');
40 signInWithPopup(auth, provider)
41 .then(function (result) {
42 if (!result) return;
43 const credential = GoogleAuthProvider.credentialFromResult(result);
44 // This gives you a Google Access Token. You can use it to access the Google API.
45 const token = credential?.accessToken;
46 // The signed-in user info.
47 const user = result.user;
48 oauthToken.textContent = token ?? '';
49 })
50 .catch(function (error) {
51 // Handle Errors here.
52 const errorCode = error.code;
53 const errorMessage = error.message;
54 // The email of the user's account used.
55 const email = error.email;
56 // The firebase.auth.AuthCredential type that was used.
57 const credential = error.credential;
58 if (errorCode === 'auth/account-exists-with-different-credential') {
59 alert(
60 'You have already signed up with a different auth provider for that email.',
61 );
62 // If you are using multiple auth providers on your app you should handle linking
63 // the user's accounts here.
64 } else {
65 console.error(error);
66 }
67 });
68 } else {
69 signOut(auth);
70 }
71 signInButton.disabled = true;
72}
73
74// Listening for auth state changes.
75onAuthStateChanged(auth, function (user) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected