Skip to content

Commit

Permalink
feat: uma função que permite realizar a conexão ao google sheets
Browse files Browse the repository at this point in the history
Conexão com o Google Sheets #26
  • Loading branch information
pauloh-fm committed Jul 13, 2024
1 parent dd293fa commit 79e3167
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .env.example
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=
21 changes: 21 additions & 0 deletions src/utils/googleSheetsConexion.ts
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 });
};

0 comments on commit 79e3167

Please sign in to comment.