2
0
Files
bot/apps/builder/pages/api/credentials/google-sheets/consent-url.ts
Baptiste Arnaud 8501d39234 build: 🏗️ Add Sentry to builder
2022-02-14 10:57:57 +01:00

24 lines
728 B
TypeScript

import { withSentry } from '@sentry/nextjs'
import { oauth2Client } from 'libs/google-sheets'
import { NextApiRequest, NextApiResponse } from 'next'
export const googleSheetsScopes = [
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive.readonly',
]
const handler = (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'GET') {
const url = oauth2Client.generateAuthUrl({
access_type: 'offline',
scope: googleSheetsScopes,
prompt: 'consent',
state: Buffer.from(JSON.stringify(req.query)).toString('base64'),
})
res.status(301).redirect(url)
}
}
export default withSentry(handler)