| 1 | import { randomBytes } from "crypto"; |
| 2 | import { NextResponse, type |
| 3 | import { getAuth } |
| 4 | import { getAppUrl, getOperatorGDriveConfig |
| 5 | |
| 6 | export async function GET |
| 7 | const auth = |
| 8 | const session = |
| 9 | if (!session) |
| 10 | |
| 11 | const config = |
| 12 | if (!config) |
| 13 | |
| 14 | const appUrl = |
| 15 | if (!appUrl) |
| 16 | |
| 17 | const state = |
| 18 | const redirectUri = |
| 19 | |
| 20 | const params = |
| 21 | client_id: config.clientId |
| 22 | redirect_uri: redirectUri, |
| 23 | response_type: "code", |
| 24 | scope: "https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/userinfo.email", |
| 25 | access_type: "offline", |
| 26 | prompt: "consent", |
| 27 | state, |
| 28 | }); |
| 29 | |
| 30 | const res = |
| 31 | `https://accounts.google.com/o/oauth2/v2/auth?${params.toString |
| 32 | ); |
| 33 | res.cookies.set |
| 34 | httpOnly: true, |
| 35 | sameSite: "lax", |
| 36 | path: "/", |
| 37 | maxAge: 600, |
| 38 | secure: process.env |
| 39 | }); |
| 40 | return res; |
| 41 | } |