2
0
Files
bot/apps/builder/pages/api/credentials/google-sheets/consent-url.ts

24 lines
728 B
TypeScript
Raw Normal View History

2022-02-14 10:57:57 +01:00
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'),
})
2022-02-14 10:57:57 +01:00
res.status(301).redirect(url)
}
}
2022-02-14 10:57:57 +01:00
export default withSentry(handler)