kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
8a5a9b421e
commit
092ce0fc8e
|
@ -52,6 +52,12 @@ export class AgenticApiClient {
|
|||
return this.getAuthSession()
|
||||
}
|
||||
|
||||
async clearAuthSession(): Promise<void> {
|
||||
this.ky = this.ky.extend({
|
||||
headers: {}
|
||||
})
|
||||
}
|
||||
|
||||
async getUser({
|
||||
userId,
|
||||
...searchParams
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue