Skip to content
17 changes: 8 additions & 9 deletions packages/cli-v3/src/commands/whoami.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { spinner } from "../utilities/windows.js";
import { loadConfig } from "../config.js";
import { resolveLocalEnvVars } from "../utilities/localEnvVars.js";
import { tryCatch } from "@trigger.dev/core";
import { readAuthConfigCurrentProfileName } from "../utilities/configFiles.js";

type WhoAmIResult =
| {
Expand Down Expand Up @@ -73,8 +74,10 @@ export async function whoAmI(
embedded: boolean = false,
silent: boolean = false
): Promise<WhoAmIResult> {
const profileToUse = options?.profile ?? readAuthConfigCurrentProfileName();

if (!embedded) {
intro(`Displaying your account details [${options?.profile ?? "default"}]`);
intro(`Displaying your account details [${profileToUse}]`);
}

const envVars = resolveLocalEnvVars(options?.envFile);
Expand All @@ -101,7 +104,7 @@ export async function whoAmI(
loadingSpinner.start("Checking your account details");
}

const authentication = await isLoggedIn(options?.profile);
const authentication = await isLoggedIn(profileToUse);

if (!authentication.ok) {
if (authentication.error === "fetch failed") {
Expand All @@ -110,15 +113,11 @@ export async function whoAmI(
if (embedded) {
!silent &&
loadingSpinner.stop(
`Failed to check account details. You may want to run \`trigger.dev logout --profile ${
options?.profile ?? "default"
}\` and try again.`
`Failed to check account details. You may want to run \`trigger.dev logout --profile ${profileToUse}\` and try again.`
);
} else {
loadingSpinner.stop(
`You must login first. Use \`trigger.dev login --profile ${
options?.profile ?? "default"
}\` to login.`
`You must login first. Use \`trigger.dev login --profile ${profileToUse}\` to login.`
);
outro(`Whoami failed: ${authentication.error}`);
}
Expand Down Expand Up @@ -148,7 +147,7 @@ export async function whoAmI(
`User ID: ${userData.data.userId}
Email: ${userData.data.email}
URL: ${chalkLink(authentication.auth.apiUrl)}`,
`Account details [${authentication.profile}]`
`Account details [${profileToUse}]`
);

const { project } = userData.data;
Expand Down