Use JWT Token connect Google Auth on NextJS
you don't need Credentials Json File
Couldn't connect using the google credentials file. Provided the link with the following codes without using JSON.
const jwt = new google.auth.JWT(
process.env.GOOGLE_SHEETS_CLIENT_EMAIL,
null,
process.env.GOOGLE_SHEETS_PRIVATE_KEY.replace(/\\n/g, '\n'),
scopes
);
const sheets = google.sheets({ version: "v4", auth: jwt });
GOOGLE_SHEETS_PRIVATE_KEY
There is an important detail for the GOOGLE_SHEETS_PRIVATE_KEY environment variable. please add "\n" as character at start
"\n-----BEGIN PRIVATE KEY-----\nxxxxxxxxxxxx=\n-----END PRIVATE KEY-----\n"