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