()
| 100 | |
| 101 | // Adds a message to the Realtime Database by calling the `addMessage` server-side function. |
| 102 | function addMessage() { |
| 103 | const messageTextInput = messageText.value; |
| 104 | addMessageButton.disabled = true; |
| 105 | const addMessage = httpsCallable(functions, 'addMessage'); |
| 106 | addMessage({ text: messageTextInput }).then(function(result) { |
| 107 | // Read result of the Cloud Function. |
| 108 | const data = result.data as { text: string }; |
| 109 | const sanitizedMessage = data.text; |
| 110 | if (messageTextInput !== sanitizedMessage) { |
| 111 | window.alert('You were naughty. Your message was sanitized to:\n\n' + sanitizedMessage); |
| 112 | } |
| 113 | messageText.value = ''; |
| 114 | addMessageButton.disabled = false; |
| 115 | }).catch(function(error) { |
| 116 | // Getting the Error details. |
| 117 | const code = error.code; |
| 118 | const message = error.message; |
| 119 | const details = error.details; |
| 120 | console.error('There was an error when calling the Cloud Function', error); |
| 121 | window.alert('There was an error when calling the Cloud Function:\n\nError Code: ' |
| 122 | + code + '\nError Message:' + message + '\nError Details:' + details); |
| 123 | addMessageButton.disabled = false; |
| 124 | }); |
| 125 | } |
| 126 | |
| 127 | // Start the Firebase signs-in flow via Google account. |
| 128 | async function signIn() { |
nothing calls this directly
no outgoing calls
no test coverage detected