(team)
| 74 | |
| 75 | // [START cloudrun_end_user_token] |
| 76 | async function vote(team) { |
| 77 | if (firebase.auth().currentUser) { |
| 78 | // Retrieve JWT to identify the user to the Identity Platform service. |
| 79 | // Returns the current token if it has not expired. Otherwise, this will |
| 80 | // refresh the token and return a new one. |
| 81 | try { |
| 82 | const token = await firebase.auth().currentUser.getIdToken(); |
| 83 | const response = await fetch('/', { |
| 84 | method: 'POST', |
| 85 | headers: { |
| 86 | 'Content-Type': 'application/x-www-form-urlencoded', |
| 87 | Authorization: `Bearer ${token}`, |
| 88 | }, |
| 89 | body: 'team=' + team, // send application data (vote) |
| 90 | }); |
| 91 | if (response.ok) { |
| 92 | const text = await response.text(); |
| 93 | window.alert(text); |
| 94 | window.location.reload(); |
| 95 | } |
| 96 | } catch (err) { |
| 97 | console.log(`Error when submitting vote: ${err}`); |
| 98 | window.alert('Something went wrong... Please try again!'); |
| 99 | } |
| 100 | } else { |
| 101 | window.alert('User not signed in.'); |
| 102 | } |
| 103 | } |
| 104 | // [END cloudrun_end_user_token] |
nothing calls this directly
no outgoing calls
no test coverage detected