feat: get the currently logged-in user information

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/588/head
Ryan Wang 2022-07-04 12:33:00 +08:00
parent 1d09bc5af3
commit ace341efef
3 changed files with 17 additions and 5 deletions

View File

@ -9,6 +9,7 @@ import {
VTag,
} from "@halo-dev/components";
import type { MenuGroupType, MenuItemType } from "@/types/menus";
import type { User } from "../../../../src/types/extension";
import logo from "@/assets/logo.svg";
import { RouterView, useRoute, useRouter } from "vue-router";
import { inject, ref } from "vue";
@ -22,8 +23,10 @@ const moreMenuVisible = ref(false);
const moreMenuRootVisible = ref(false);
const spotlight = ref(false);
const currentUser = inject<User>("currentUser");
const handleRouteToProfile = () => {
router.push({ path: "/users/profile/detail" });
router.push({ path: `/users/${currentUser?.metadata.name}/detail` });
};
</script>
@ -47,11 +50,13 @@ const handleRouteToProfile = () => {
</div>
<VRoutesMenu :menus="menus" />
<div class="current-profile">
<div class="profile-avatar">
<img class="h-11 w-11 rounded-full" src="https://ryanc.cc/avatar" />
<div v-if="currentUser.spec.avatar" class="profile-avatar">
<img :src="currentUser.spec.avatar" class="h-11 w-11 rounded-full" />
</div>
<div class="profile-name">
<div class="flex text-sm font-medium">Ryan Wang</div>
<div class="flex text-sm font-medium">
{{ currentUser.spec.displayName }}
</div>
<div class="flex">
<VTag>
<template #leftIcon>

View File

@ -17,6 +17,7 @@ import { setupComponents } from "./setup/setupComponents";
import { coreModules } from "./modules";
import { useScriptTag } from "@vueuse/core";
import { usePluginStore } from "@/stores/plugin";
import type { User } from "@/types/extension";
const app = createApp(App);
@ -130,6 +131,11 @@ async function loadPluginModules() {
}
}
async function loadCurrentUser() {
const response = await axiosInstance.get(`/custom-api/v1alpha1/users/me`);
app.provide<User>("currentUser", response.data);
}
(async function () {
await initApp();
})();
@ -138,6 +144,7 @@ async function initApp() {
try {
loadCoreModules();
await loadPluginModules();
await loadCurrentUser();
app.provide<MenuGroupType[]>("menus", menus);
app.provide<MenuItemType[]>("minimenus", minimenus);
} catch (e) {

View File

@ -25,7 +25,7 @@ const loginForm = ref<LoginFormState>({
state: {
_csrf: "",
username: "admin",
password: "wsYdVrLTYnLbzN6e",
password: "{no}123456",
},
});