diff --git a/cli/context.ts b/cli/context.ts index 1b5574a3d6..fc092cd66d 100644 --- a/cli/context.ts +++ b/cli/context.ts @@ -1,5 +1,5 @@ // deno-lint-ignore-file no-explicit-any -import { colors, setClient, UserService } from "./deps.ts"; +import { colors, GlobalUserInfo, setClient, UserService } from "./deps.ts"; import { loginInteractive, tryGetLoginInfo } from "./login.ts"; import { GlobalOptions } from "./types.ts"; import { @@ -60,7 +60,7 @@ export async function resolveWorkspace( } } -export async function requireLogin(opts: GlobalOptions) { +export async function requireLogin(opts: GlobalOptions): Promise { const workspace = await resolveWorkspace(opts); let token = await tryGetLoginInfo(opts); @@ -71,7 +71,7 @@ export async function requireLogin(opts: GlobalOptions) { setClient(token, workspace.remote.substring(0, workspace.remote.length - 1)); try { - await UserService.globalWhoami(); + return await UserService.globalWhoami(); } catch { console.log( "! Could not reach API given existing credentials. Attempting to reauth...", @@ -88,7 +88,7 @@ export async function requireLogin(opts: GlobalOptions) { token, workspace.remote.substring(0, workspace.remote.length - 1), ); - await UserService.globalWhoami(); + return await UserService.globalWhoami(); } } diff --git a/cli/hub.ts b/cli/hub.ts index 526df43bbc..bb28cc701f 100644 --- a/cli/hub.ts +++ b/cli/hub.ts @@ -13,7 +13,7 @@ async function pull(opts: GlobalOptions) { return; } - await requireLogin(opts); + const userInfo = await requireLogin(opts); const list: { id: number; name: string; @@ -26,6 +26,12 @@ async function pull(opts: GlobalOptions) { comments: never[]; }[] = await fetch( "https://hub.windmill.dev/resource_types/list", + { + headers: { + "Accept": "application/json", + "X-email": userInfo.email, + }, + }, ) .then((r) => r.json()) .then((list: { id: number; name: string }[]) =>