Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.1 KB
Raw Blame
import type { CommandContext } from '@/plugins/base'
import { z } from 'zod'
import { assertNotEnvLogin, revokeAndClearSession } from '@/auth/logout'
import { pendingLoginStore } from '@/auth/pending-login'
import { Command } from '@/plugins/commands/command'
import { session } from '@/plugins/session'

const INPUT = z.object({})

const ENV_LOGOUT_MESSAGE = 'nothing to log out: the login comes from DIFY_TOKEN'

export default class Logout extends Command<typeof INPUT> {
  static override summary = 'Log out of the current Dify session'
  static override effect = 'write' as const
  static override input = INPUT

  async run(_input: z.infer<typeof INPUT>, ctx: CommandContext) {
    const sessionService = await ctx.get(session)
    // Refuse before touching anything: an env login must leave a pending interactive login alone.
    assertNotEnvLogin(sessionService.fromEnv, ENV_LOGOUT_MESSAGE)
    await (await pendingLoginStore(ctx)).clear()
    const login = await sessionService.require()
    await revokeAndClearSession(ctx, login)

    return { logged_out: true, server: login.server }
  }
}