-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: uma função que permite realizar a conexão ao google sheets
Conexão com o Google Sheets #26
- Loading branch information
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
GOOGLE_CLIENT_EMAIL= | ||
GOOGLE_PRIVATE_KEY= | ||
GOOGLE_SHEET_ID= | ||
SHEET_NAME= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { google } from "googleapis"; | ||
|
||
export const getGoogleSheetsClient = () => { | ||
const { GOOGLE_CLIENT_EMAIL, GOOGLE_PRIVATE_KEY } = process.env; | ||
|
||
if (!GOOGLE_CLIENT_EMAIL || !GOOGLE_PRIVATE_KEY) { | ||
throw new Error( | ||
"Não foi possivel carregar as variaveis de ambiente da Google Cloud", | ||
); | ||
} | ||
|
||
const auth = new google.auth.GoogleAuth({ | ||
credentials: { | ||
client_email: GOOGLE_CLIENT_EMAIL, | ||
private_key: GOOGLE_PRIVATE_KEY.replace(/\\n/g, "\n"), | ||
}, | ||
scopes: ["https://www.googleapis.com/auth/spreadsheets"], | ||
}); | ||
|
||
return google.sheets({ version: "v4", auth }); | ||
}; |