: 🔒️ Investigate on why spreadsheets sometimes fail
This commit is contained in:
@ -1,8 +1,13 @@
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { drive } from '@googleapis/drive'
|
||||
import { getAuthenticatedGoogleClient } from 'libs/google-sheets'
|
||||
import { badRequest, methodNotAllowed, notAuthenticated } from 'utils'
|
||||
import { setUser, withSentry } from '@sentry/nextjs'
|
||||
import {
|
||||
badRequest,
|
||||
forbidden,
|
||||
methodNotAllowed,
|
||||
notAuthenticated,
|
||||
} from 'utils'
|
||||
import { captureException, setUser, withSentry } from '@sentry/nextjs'
|
||||
import { getAuthenticatedUser } from 'services/api/utils'
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
@ -16,9 +21,18 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const auth = await getAuthenticatedGoogleClient(user.id, credentialsId)
|
||||
if (!auth)
|
||||
return res.status(404).send("Couldn't find credentials in database")
|
||||
console.log(auth.credentials.name, user.email)
|
||||
if (auth.credentials.name !== user.email) {
|
||||
captureException(
|
||||
new Error(
|
||||
`Credentials name does not match user email ${auth?.credentials.name} !== ${user.email}`
|
||||
)
|
||||
)
|
||||
return forbidden(res)
|
||||
}
|
||||
const response = await drive({
|
||||
version: 'v3',
|
||||
auth: auth,
|
||||
auth: auth.client,
|
||||
}).files.list({
|
||||
q: "mimeType='application/vnd.google-apps.spreadsheet'",
|
||||
fields: 'nextPageToken, files(id, name)',
|
||||
|
@ -21,12 +21,12 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
|
||||
const spreadsheetId = req.query.id.toString()
|
||||
const doc = new GoogleSpreadsheet(spreadsheetId)
|
||||
const client = await getAuthenticatedGoogleClient(user.id, credentialsId)
|
||||
if (!client)
|
||||
const auth = await getAuthenticatedGoogleClient(user.id, credentialsId)
|
||||
if (!auth)
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: "Couldn't find credentials in database" })
|
||||
doc.useOAuth2Client(client)
|
||||
doc.useOAuth2Client(auth.client)
|
||||
await doc.loadInfo()
|
||||
return res.send({
|
||||
sheets: (
|
||||
|
Reference in New Issue
Block a user