add email to cli resource fetching

This commit is contained in:
Ruben Fiszel
2023-02-14 14:27:24 +01:00
parent 8c3ace631e
commit 5abb1e46c0
2 changed files with 11 additions and 5 deletions
+4 -4
View File
@@ -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<GlobalUserInfo> {
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();
}
}
+7 -1
View File
@@ -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 }[]) =>