Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

290
Vistas
Consuming BigQuery API Client through middleware and locating secrets.json files

I want to use a secrets folder to store my bigquery api client secrets json and use BigQuery client library for node to make queries to the database. But in the documentations, it shows way to load credentials from a json file and not directly.

I am using typescript to query a table and append row, In NEXT js, I am a littlebit confused about how to access the path of a secrets folder that's not going to be exposed to client side and stays in for my middleware.

Here's the function for the same:

import type { NextApiHandler } from 'next';
import axios from 'axios';
import { BigQuery } from '@google-cloud/bigquery';
import bqSecrets from '../../../bigquery/keys.json';
const options = {
  keyFilename: '../../../secrets/keys.json',
  projectId: 'XXXXXXXXXXXXXXXXXXXXXX',
};

const bigquery = new BigQuery(options);

const submitUserData: NextApiHandler = async (request, response) => {
  const { geoData, googleData, post, userRole } = request.body;
  if (!post) response.json({ error: false, msg: 'Not Required' });
  else {
    delete googleData.isAuthenticated;

    

    try {
      const rep = await bigquery
        .dataset('stackconnect')
        .table('googleoAuth')
        .insert([requestPayload]);
      console.log(await rep);
      response.json({ error: false, msg: 'Success' });
    } catch (e) {
      console.log('Error = ', e);
      response.json({ error: true, msg: 'Error' });
    }
  }
};

But this throws an error saying: File not Found. Can someone help me identify about how to either locate the file in NEXT or how can I directly pass the JSON data using BQ Node Client?

Additionally, I want to know in NEXT, which is the ideal place to store secrets that are not exposed to client side?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

After digging into the source code, I realized that there's an attribute called credentials, and so I was able to make it work by doing the following modification:

import bqSecrets from '../../../bigquery/keys.json';
const options = {
  credentials: bqSecrets,
  projectId: 'project_id',
};

const bigquery = new BigQuery(options);

I hope this helps anyone who's looking to directly inject the json credentials to the BigQuery Node Client.

Additionally, I am still not very sure about the file structure of NEXT as I still don't know if any other assets than those placed under public folder are exposed to client side or not.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda