I am exploring the idea of utilizing a secrets folder to securely store my BigQuery API client secrets JSON file and leveraging the BigQuery
client library for Node.js to execute queries on the database. However, the documentation seems to focus on loading credentials from a JSON file indirectly rather than directly.
As I am working with TypeScript to query a table and add rows, I find myself a bit perplexed when it comes to accessing the path of a secrets folder that needs to be kept confidential and not accessible to the client side, especially within my middleware setup in NEXT.js.
Below is the code snippet for reference:
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' });
}
}
};
However, this results in an error stating: File not Found
. Can anyone assist me in understanding how to either locate the file in NEXT.js or how to directly pass the JSON data using the BigQuery Node Client?
Furthermore, I am curious to know where the most suitable place in NEXT.js would be to securely store sensitive information that is not supposed to be exposed to the client side.