Eray Bartan
Eray Bartan Blog

Eray Bartan Blog

Use JWT Token connect Google Auth on NextJS

Use JWT Token connect Google Auth on NextJS

you don't need Credentials Json File

Eray Bartan's photo
Eray Bartan
·Aug 20, 2021·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

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_PRIVATE_KEY.replace(/\\n/g, '\n'),

    const sheets = google.sheets({ version: "v4", auth: jwt });


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"
Share this