mirror of https://github.com/halo-dev/halo-admin
Browse Source
#### What type of PR is this? /kind improvement /milestone 2.0 #### What this PR does / why we need it: 使用 Pinia 管理已授权用户信息,并提供判断是否是 `anonymousUser` 的方式。 适配 https://github.com/halo-dev/halo/pull/2729 #### Special notes for your reviewer: /cc @halo-dev/sig-halo-console 测试流程: 1. Halo 需要切换到 https://github.com/halo-dev/halo/pull/2729 的分支。 2. 测试 Console 端的登录、退出等流程。 #### Does this PR introduce a user-facing change? ```release-note None ```pull/703/head
Ryan Wang
2 years ago
committed by
GitHub
8 changed files with 77 additions and 36 deletions
@ -0,0 +1,26 @@
|
||||
import { apiClient } from "@/utils/api-client"; |
||||
import type { User } from "@halo-dev/api-client"; |
||||
import { defineStore } from "pinia"; |
||||
|
||||
interface UserStoreState { |
||||
currentUser?: User; |
||||
isAnonymous: boolean; |
||||
} |
||||
|
||||
export const useUserStore = defineStore("user", { |
||||
state: (): UserStoreState => ({ |
||||
currentUser: undefined, |
||||
isAnonymous: true, |
||||
}), |
||||
actions: { |
||||
async fetchCurrentUser() { |
||||
try { |
||||
const { data } = await apiClient.user.getCurrentUserDetail(); |
||||
this.currentUser = data; |
||||
this.isAnonymous = data.metadata.name === "anonymousUser"; |
||||
} catch (e) { |
||||
console.error("Failed to fetch current user", e); |
||||
} |
||||
}, |
||||
}, |
||||
}); |
Loading…
Reference in new issue