From 092ce0fc8e65c52a03fffa36515f4ba2c1ac3fcc Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Fri, 23 May 2025 00:23:39 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/api-client/src/agentic-api-client.ts | 6 +++++ packages/cli/src/commands/signout.ts | 22 +++++++++++++++++++ packages/cli/src/commands/whoami.ts | 6 ++--- packages/cli/src/index.ts | 2 ++ 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 packages/cli/src/commands/signout.ts diff --git a/packages/api-client/src/agentic-api-client.ts b/packages/api-client/src/agentic-api-client.ts index f8b468b9..f6657251 100644 --- a/packages/api-client/src/agentic-api-client.ts +++ b/packages/api-client/src/agentic-api-client.ts @@ -52,6 +52,12 @@ export class AgenticApiClient { return this.getAuthSession() } + async clearAuthSession(): Promise { + this.ky = this.ky.extend({ + headers: {} + }) + } + async getUser({ userId, ...searchParams diff --git a/packages/cli/src/commands/signout.ts b/packages/cli/src/commands/signout.ts new file mode 100644 index 00000000..f4d41694 --- /dev/null +++ b/packages/cli/src/commands/signout.ts @@ -0,0 +1,22 @@ +import { Command } from 'commander' + +import type { Context } from '../types' +import { AuthStore } from '../store' + +export function registerSignoutCommand({ client, program, logger }: Context) { + const command = new Command('logout') + .alias('signout') + .description('Signs the current user out') + .action(async () => { + if (!AuthStore.isAuthenticated()) { + return + } + + await client.clearAuthSession() + AuthStore.clearAuth() + + logger.log('Signed out') + }) + + program.addCommand(command) +} diff --git a/packages/cli/src/commands/whoami.ts b/packages/cli/src/commands/whoami.ts index a8a4403c..4ca0e883 100644 --- a/packages/cli/src/commands/whoami.ts +++ b/packages/cli/src/commands/whoami.ts @@ -3,17 +3,17 @@ import { Command } from 'commander' import type { Context } from '../types' import { AuthStore } from '../store' -export function registerWhoAmICommand({ client, program }: Context) { +export function registerWhoAmICommand({ client, program, logger }: Context) { const command = new Command('whoami') .description('Displays info about the current user') .action(async () => { if (!AuthStore.isAuthenticated()) { - console.log('Not signed in') + logger.log('Not signed in') return } const res = await client.getAuthSession() - console.log(res) + logger.log(res) }) program.addCommand(command) diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index f89039e1..f30cce17 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -5,6 +5,7 @@ import { Command } from 'commander' import restoreCursor from 'restore-cursor' import { registerSigninCommand } from './commands/signin' +import { registerSignoutCommand } from './commands/signout' import { registerWhoAmICommand } from './commands/whoami' import { AuthStore } from './store' @@ -41,6 +42,7 @@ async function main() { // Register all commands registerSigninCommand(ctx) registerWhoAmICommand(ctx) + registerSignoutCommand(ctx) program.parse() }