From 6fc538c4ecca39d0ae240cb8de8c4ff4393ddc5a Mon Sep 17 00:00:00 2001 From: phorvicheka Date: Fri, 8 Mar 2024 10:33:55 +0900 Subject: [PATCH] fix: condition on prompt auth (prompts for authentication if an ORM is present and config.auth is falsy, either undefined or null.) --- src/commands/add/index.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/commands/add/index.ts b/src/commands/add/index.ts index feace154..d27425cc 100644 --- a/src/commands/add/index.ts +++ b/src/commands/add/index.ts @@ -94,17 +94,19 @@ const promptUser = async (options?: InitOptions): Promise => { if (usePscale) dbProvider = "planetscale"; } - const auth = config.auth || !orm ? undefined : await askAuth(options); + // prompt auth + const hasOrm = !!config.orm || !!orm; + const auth = !hasOrm ? undefined : !config.auth ? await askAuth(options) : undefined; + // prompt auth provider const authProviders = auth === "next-auth" ? options?.authProviders || (await askAuthProvider()) : undefined; - const hasOrmAndAuth = !!( - config.auth || - (auth && auth !== null && (config.orm || (orm && orm !== null))) - ); + // prompt misc packages + const hasAuth = !!config.auth || !!auth; + const hasOrmAndAuth = hasOrm && hasAuth; const packagesToInstall = options.miscPackages || (await askMiscPackages(config.packages, hasOrmAndAuth)); @@ -198,9 +200,13 @@ export const addPackage = async ( } if (promptResponse === null) updateConfigFile({ orm: null, driver: null, provider: null }); + } else { + promptResponse.orm = config.orm; + promptResponse.db = config.driver; + promptResponse.dbProvider = config.provider; } // check if auth - if (config.auth === undefined) { + if (!config.auth) { if (promptResponse.auth && promptResponse.auth !== null) spinner.text = "Configuring " +