The component that I have doing an API call looks like this:
import React from 'react';
import { Button } from 'react-bootstrap';
class Middle extends React.Component {
handleClick() {
console.log('this is:', this);
}
// This syntax ensures `this` is bound within handleClick. // Warning: this is *experimental* syntax. handleClick = () => { console.log('this is:', this); }
async fetchNonce() {
const response = await fetch("http://localhost:<PORT NUMBER HERE>/path/to/endpoint")
console.log(response.status)
const data = await response.json()
console.log(data)
}
render() {
return (
<div className="col-md-12 text-center">
<Button variant='primary' onClick={this.fetchNonce}>
Click me
</Button>
</div>
);
}
}
export default Middle;
The above code works for a simple throw away local node that I'm running for testing purposes. I want to use the above code to, instead of running a local function, reach out to Google Cloud Functions and run one of my Google Cloud Functions instead.
I created a Google Cloud Platform account, and made a simple hello_world type Python "Cloud Function" that just spits out some simple text. I made this function "HTTP" accessible and only able to be called/authenticated by a "Service Account" that I made for the purpose of calling this very function. I generated a key for this "Service Account" and downloaded the json file for the key.
I've seen a lot of tutorials on how to call functions via an authenticated "Service Account" but I'm concerned that a lot of methods might not be secure or following best practices. What is the best practices way to modify the above code to call a Google Cloud Function and authenticate with my "Service Account?"