diff --git a/garden-service/src/cli/cli.ts b/garden-service/src/cli/cli.ts index dd8e87a7d1..ee6e0f796e 100644 --- a/garden-service/src/cli/cli.ts +++ b/garden-service/src/cli/cli.ts @@ -98,7 +98,7 @@ export async function makeDummyGarden(root: string, gardenOpts: GardenOpts = {}) } gardenOpts.config = config - return DummyGarden.factory(root, gardenOpts) + return DummyGarden.factory(root, { ...gardenOpts, noPlatform: true }) } // The help text for these commands is only displayed when calling `garden options`. diff --git a/garden-service/src/cloud/auth.ts b/garden-service/src/cloud/auth.ts index b8ace9741a..8b4193625b 100644 --- a/garden-service/src/cloud/auth.ts +++ b/garden-service/src/cloud/auth.ts @@ -61,7 +61,7 @@ export async function login(platformUrl: string, log: LogEntry): Promise /** * Checks with the backend whether the provided client auth token is valid. */ -async function checkClientAuthToken(token: string, platformUrl: string, log: LogEntry): Promise { +export async function checkClientAuthToken(token: string, platformUrl: string, log: LogEntry): Promise { let valid try { await got({ diff --git a/garden-service/src/garden.ts b/garden-service/src/garden.ts index 35e4c69c31..0ebe522beb 100644 --- a/garden-service/src/garden.ts +++ b/garden-service/src/garden.ts @@ -61,7 +61,7 @@ import { deline, naturalList } from "./util/string" import { ensureConnected } from "./db/connection" import { DependencyValidationGraph } from "./util/validate-dependencies" import { Profile } from "./util/profiling" -import { readAuthToken, login } from "./cloud/auth" +import { readAuthToken, checkClientAuthToken } from "./cloud/auth" import { ResolveModuleTask, getResolvedModules } from "./tasks/resolve-module" import username from "username" @@ -96,6 +96,7 @@ export interface GardenOpts { log?: LogEntry plugins?: RegisterPluginParam[] sessionId?: string + noPlatform?: boolean } export interface GardenParams { @@ -291,7 +292,7 @@ export class Garden { const clientAuthToken = await readAuthToken(log) // If a client auth token exists in local storage, we assume that the user wants to be logged in to the platform. - if (clientAuthToken && sessionId) { + if (clientAuthToken && !opts.noPlatform) { if (!platformUrl) { const errMsg = deline` GARDEN_CLOUD environment variable is not set. Make sure it is set to the appropriate API @@ -299,7 +300,14 @@ export class Garden { prefix).` throw new InternalError(errMsg, {}) } else { - await login(platformUrl, log) + const tokenIsValid = await checkClientAuthToken(clientAuthToken, platformUrl, log) + if (!tokenIsValid) { + log.warn(deline` + You were previously logged in to the platform, but your session has expired or is invalid. Please run + ${chalk.bold("garden login")} to continue using platform features, or run ${chalk.bold("garden logout")} + to suppress this message. + `) + } } }