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

Function toggleSignIn

auth/apple-popup.ts:35–76  ·  view source on GitHub ↗

* Function called when clicking the Login/Logout button.

()

Source from the content-addressed store, hash-verified

33 * Function called when clicking the Login/Logout button.
34 */
35function toggleSignIn() {
36 if (!auth.currentUser) {
37 const provider = new OAuthProvider('apple.com');
38
39 provider.addScope('email');
40 provider.addScope('name');
41
42 signInWithPopup(auth, provider)
43 .then(function (result) {
44 // The signed-in user info.
45 const user = result.user;
46
47 const credential = OAuthProvider.credentialFromResult(result)!;
48 // You can also get the Apple OAuth Access and ID Tokens.
49 const accessToken = credential.accessToken;
50 const idToken = credential.idToken;
51
52 oauthToken.textContent = idToken ?? null;
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 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 auth.signOut();
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