dify_admin/docs/web/store.md

885 B

State Management Documentation

Architecture

  • Library: Pinia (Vue 3 recommended state management)
  • Structure: Modular stores
  • Reactivity: Composition API style

User Store

State Properties

  • token: Authentication token
  • userInfo: User profile data

Methods

  • setToken(token): Updates token in store and localStorage
  • setUserInfo(info): Updates user profile
  • login(params): Handles login flow
    • Parameters: {username, password}
    • Returns: {access_token}
  • getUserInfo(): Returns current user info

Persistence

  • Token is automatically synced with localStorage
  • Uses utils/storage helper methods

Usage Example

import { useUserStore } from '@/store'

const userStore = useUserStore()

// Login
await userStore.login({username: 'test', password: '123'})

// Get user info
const user = userStore.getUserInfo()