Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Jan 16, 2025
1 parent 32da5e4 commit 5a1699b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 0 additions & 6 deletions packages/cli/src/commands/auth/whoami.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { outro } from "@clack/prompts";
import chalk from "chalk";
import { client } from "../../utils/api.ts";

export async function whoamiCommand() {
const user = await client.user.me.query();

if (!user) {
outro("You are not logged in. Run `languine auth login` to authenticate.");
return;
}

const details = [
["Name", user.name],
["Email", user.email],
Expand Down
18 changes: 18 additions & 0 deletions packages/cli/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { loadEnv } from "@/utils/env.js";
import { getAPIKey } from "@/utils/session.js";
import type { AppRouter } from "@languine/web/src/trpc/routers/_app.js";
import { createTRPCClient, httpBatchLink, loggerLink } from "@trpc/client";
import chalk from "chalk";
import superjson from "superjson";

loadEnv();
Expand All @@ -22,6 +23,23 @@ export const client = createTRPCClient<AppRouter>({
"x-trpc-source": "cli",
};
},
fetch: (url, options) => {
return fetch(url, options).then(async (res) => {
if (!res.ok) {
const error = await res.json().catch(() => null);

if (error[0]?.error?.json?.message === "UNAUTHORIZED") {
console.log(
chalk.red(
"You are not logged in. Please run `languine auth login` first.",
),
);
process.exit(1);
}
}
return res;
});
},
}),
],
});

0 comments on commit 5a1699b

Please sign in to comment.