mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
fix reading credentials
This commit is contained in:
@@ -1,14 +1,20 @@
|
|||||||
import { google } from 'googleapis'
|
import { google } from 'googleapis'
|
||||||
import { Booking } from '../db/booking'
|
import { Booking } from '../db/booking'
|
||||||
|
|
||||||
const keyFile = process.env.GOOGLE_SERVICE_ACCOUNT_KEY_FILE
|
|
||||||
const calendarId = process.env.GOOGLE_CALENDAR_ID
|
const calendarId = process.env.GOOGLE_CALENDAR_ID
|
||||||
|
let credentials
|
||||||
|
|
||||||
|
try {
|
||||||
|
credentials = JSON.parse(process.env.GOOGLE_SERVICE_ACCOUNT_KEY_JSON);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Unable to parse process.env.GOOGLE_SERVICE_ACCOUNT_KEY_JSON - invalid JSON?');
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
const auth = new google.auth.GoogleAuth({
|
const auth = new google.auth.GoogleAuth({
|
||||||
keyFile,
|
credentials,
|
||||||
scopes: [
|
scopes: [
|
||||||
'https://www.googleapis.com/auth/calendar',
|
'https://www.googleapis.com/auth/calendar',
|
||||||
'https://www.googleapis.com/auth/calendar.readonly',
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -39,8 +45,9 @@ function getSummary(booking: Partial<Booking>): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function createCalendarEvent(booking: Booking): Promise<Booking> {
|
export async function createCalendarEvent(booking: Booking): Promise<Booking> {
|
||||||
|
const authInstance = await auth.getClient();
|
||||||
const response = await calendar.events.insert({
|
const response = await calendar.events.insert({
|
||||||
auth,
|
auth: authInstance,
|
||||||
calendarId,
|
calendarId,
|
||||||
requestBody: {
|
requestBody: {
|
||||||
summary: getSummary(booking),
|
summary: getSummary(booking),
|
||||||
|
|||||||
Reference in New Issue
Block a user