Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

296
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda