Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!