Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

how often do I need to call gcloud auth login?

 

I am a FE engineer working on a new company from the ground up. The "backend" world is completely foreign to me. It was suggested to use SupaBase for user authorization.
 
We are using Google VertexAI as the core of the app feature. There is a "public" REST endpoint which would look like this:
 
 

 

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d u/request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/endpoints/ENDPOINT_ID:explain"

 

 
The issue I run into trying to convert this to a `fetch` type API is that the `gcloud` commands & the oAuth expire very frequently, and storing them as a ReactNative "constant" via `process.env` isn't ideal.
 
 

 

const path = `https://us-central1-aiplatform.googleapis.com/v1/projects/${Constants.expoConfig.extra.VERTEX_PROJECT_ID}/locations/us-central1/endpoints/${Constants.expoConfig.extra.VERTEX_ENDPOINT_ID}:predict`;

const init = {
    method: 'POST',
    body: JSON.stringify(requestBody),
    headers: {
      Authorization: `Bearer ${Constants.expoConfig.extra.VERTEX_GCLOUD_ACCESS_TOKEN}`,
      'Content-Type': 'application/json',
    },
  };

const response = await fetch(path, init);

 

 
Note: The following command assumes that you have logged in to the gcloud CLI with your user account by running gcloud init or gcloud auth login, or by using Cloud Shell, which automatically logs you into the gcloud CLI. You can check the currently active account by running gcloud auth list.

Is it correct that I want to call gcloud auth login basically once, when the server is initialized so that any of my users can use the feature on the mobile app, or does this need to be called each time a request is made to the gcloud API? Then the gcloud auth print-access-token gets called for each API request.

 
0 1 3,025
1 REPLY 1

Hello @lucksp,

Welcome to Google Cloud Community!

Instead of using gcloud, you can use api keys or client libraries so users will be able to authenticate. If you encounter any errors while working on this, don't hesitate to post back here we are delighted to try and help.

Thanks!