Template
feat : guess word
This commit is contained in:
+43
-34
@@ -2,39 +2,48 @@ import { defineStore } from "pinia";
|
||||
import { UserResponseDTO } from "~/netcode/events/dto/userresponse.dto";
|
||||
|
||||
export const useUserStore = defineStore("user", {
|
||||
state: () => ({
|
||||
users: {} as Record<string, UserResponseDTO>,
|
||||
self: null as UserResponseDTO | null,
|
||||
has_contacted: false
|
||||
}),
|
||||
actions: {
|
||||
async fetchUser(id: string) {
|
||||
if (id in this.users) {
|
||||
return this.users[id]
|
||||
}
|
||||
const config = useRuntimeConfig();
|
||||
const data = await useFetch<UserResponseDTO>(config.public.endpoint + `/users/` + id, {
|
||||
credentials: "include",
|
||||
immediate: true
|
||||
})
|
||||
if (data.data.value) {
|
||||
this.users[data.data.value.id] = data.data.value
|
||||
}
|
||||
return data.data.value
|
||||
},
|
||||
async whoami() {
|
||||
const config = useRuntimeConfig();
|
||||
const req = await useFetch<UserResponseDTO>(config.public.endpoint + "/whoami", {
|
||||
credentials: "include",
|
||||
server: false,
|
||||
immediate: true,
|
||||
onResponse: (data) => {
|
||||
this.self = data.response._data
|
||||
this.has_contacted = true
|
||||
},
|
||||
lazy: true
|
||||
})
|
||||
return req;
|
||||
state: () => ({
|
||||
users: {} as Record<string, UserResponseDTO>,
|
||||
self: null as UserResponseDTO | null,
|
||||
has_contacted: false,
|
||||
}),
|
||||
actions: {
|
||||
async fetchUser(id: string) {
|
||||
if (id in this.users) {
|
||||
return this.users[id];
|
||||
}
|
||||
const config = useRuntimeConfig();
|
||||
const data = await useFetch<UserResponseDTO>(
|
||||
config.public.endpoint + `/users/` + id,
|
||||
{
|
||||
credentials: "include",
|
||||
immediate: true,
|
||||
}
|
||||
);
|
||||
if (data.data.value) {
|
||||
this.users[data.data.value.id] = data.data.value;
|
||||
}
|
||||
return data.data.value;
|
||||
},
|
||||
});
|
||||
async whoami() {
|
||||
const config = useRuntimeConfig();
|
||||
const req = await useFetch<UserResponseDTO>(
|
||||
config.public.endpoint + "/whoami",
|
||||
{
|
||||
credentials: "include",
|
||||
server: false,
|
||||
immediate: true,
|
||||
onResponse: (data) => {
|
||||
if (data.response.ok) {
|
||||
this.self = data.response._data;
|
||||
}
|
||||
|
||||
this.has_contacted = true;
|
||||
},
|
||||
lazy: true,
|
||||
}
|
||||
);
|
||||
return req;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user