| 247 | |
| 248 | // Function to prompt for Google client credentials |
| 249 | async function promptForGoogleClientCredentials() { |
| 250 | intro("Now, time for auth!"); |
| 251 | |
| 252 | const devVarsPath = path.join(__dirname, "..", ".dev.vars"); |
| 253 | |
| 254 | if (!fs.existsSync(devVarsPath)) { |
| 255 | console.log( |
| 256 | "\x1b[33mNow, we will set up authentication for your app using Google OAuth2. \nGo to https://console.cloud.google.com/, create a new project and set up OAuth consent screen.\nThen, go to Credentials > OAuth client ID and create a new client ID.\nPaste the client ID and client secret below. \n\nMore info: https://developers.google.com/workspace/guides/configure-oauth-consent#:~:text=Go%20to%20OAuth%20consent%20screen,sensitive%20scopes%2C%20and%20restricted%20scopes.\x1b[0m", |
| 257 | ); |
| 258 | const clientId = await prompt( |
| 259 | "Enter your Google Client ID (enter to skip)", |
| 260 | "", |
| 261 | ); |
| 262 | const clientSecret = await prompt( |
| 263 | "Enter your Google Client Secret (enter to skip)", |
| 264 | "", |
| 265 | ); |
| 266 | |
| 267 | try { |
| 268 | fs.writeFileSync( |
| 269 | devVarsPath, |
| 270 | `AUTH_GOOGLE_ID=${clientId}\nAUTH_GOOGLE_SECRET=${clientSecret}\n`, |
| 271 | ); |
| 272 | console.log( |
| 273 | "\x1b[33m.dev.vars file created with Google Client ID and Client Secret.\x1b[0m", |
| 274 | ); |
| 275 | } catch (error) { |
| 276 | console.error("\x1b[31mError creating .dev.vars file:", error, "\x1b[0m"); |
| 277 | cancel("Operation cancelled."); |
| 278 | } |
| 279 | } else { |
| 280 | console.log( |
| 281 | "\x1b[31m.dev.vars file already exists. Skipping creation.\x1b[0m", |
| 282 | ); |
| 283 | } |
| 284 | |
| 285 | outro(".dev.vars updated with Google Client ID and Client Secret."); |
| 286 | } |
| 287 | |
| 288 | // Function to generate secure random 32-character string |
| 289 | function generateSecureRandomString(length: number): string { |