mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-03 16:20:27 +00:00
fetch and store self in store
This commit is contained in:
parent
efcea11959
commit
8bb13f6bf4
2 changed files with 19 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
import { useAuthStore } from "~~/stores/auth";
|
||||
import { useItemStore } from "~~/stores/items";
|
||||
import { useLabelStore } from "~~/stores/labels";
|
||||
import { useLocationStore } from "~~/stores/locations";
|
||||
|
@ -12,6 +13,19 @@
|
|||
|
||||
const api = useUserApi();
|
||||
|
||||
const auth = useAuthStore();
|
||||
|
||||
if (auth.self === null) {
|
||||
const { data, error } = await api.self();
|
||||
if (error) {
|
||||
navigateTo("/login");
|
||||
}
|
||||
|
||||
auth.$patch({ self: data.item });
|
||||
|
||||
console.log(auth.self);
|
||||
}
|
||||
|
||||
const itemsStore = useItemStore();
|
||||
const items = computed(() => itemsStore.items);
|
||||
|
||||
|
@ -121,8 +135,8 @@
|
|||
<div class="sm:flex sm:space-x-5">
|
||||
<div class="mt-4 text-center sm:mt-0 sm:pt-1 sm:text-left">
|
||||
<p class="text-sm font-medium text-gray-600">Welcome back,</p>
|
||||
<p class="text-xl font-bold text-gray-900 sm:text-2xl">Username</p>
|
||||
<p class="text-sm font-medium text-gray-600">User</p>
|
||||
<p class="text-xl font-bold text-gray-900 sm:text-2xl">{{ auth.self.name }}</p>
|
||||
<p class="text-sm font-medium text-gray-600">{{ auth.self.isSuperuser ? "Admin" : "User" }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5 flex justify-center sm:mt-0">
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { useLocalStorage } from "@vueuse/core";
|
||||
import { UserApi } from "~~/lib/api/user";
|
||||
import { UserOut } from "~~/lib/api/types/data-contracts";
|
||||
|
||||
export const useAuthStore = defineStore("auth", {
|
||||
state: () => ({
|
||||
token: useLocalStorage("pinia/auth/token", ""),
|
||||
expires: useLocalStorage("pinia/auth/expires", ""),
|
||||
self: null as UserOut | null,
|
||||
}),
|
||||
getters: {
|
||||
isTokenExpired: state => {
|
||||
|
@ -30,6 +32,7 @@ export const useAuthStore = defineStore("auth", {
|
|||
|
||||
this.token = "";
|
||||
this.expires = "";
|
||||
this.self = null;
|
||||
|
||||
return result;
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue