Files
KnockOutWhist-Frontend/src/composables/useUserInfo.ts
lq64 bb6355d9ed feat(ui): FRO-34 Lobby (#21)
Started with Lobby Component

Co-authored-by: LQ63 <lkhermann@web.de>
Co-authored-by: Janis <janis-e@gmx.de>
Reviewed-on: #21
Reviewed-by: Janis <janis-e@gmx.de>
Co-authored-by: lq64 <lq@blackhole.local>
Co-committed-by: lq64 <lq@blackhole.local>
2025-12-14 15:10:27 +01:00

43 lines
1.1 KiB
TypeScript

import { defineStore } from 'pinia'
import {ref, type Ref} from 'vue'
import axios from "axios";
const api = window?.__RUNTIME_CONFIG__?.API_URL;
export const useUserInfo = defineStore('userInfo', () => {
const username: Ref<string | null> = ref(null);
const userId: Ref<number | null> = ref(null);
const gameId: Ref<string | null> = ref(null);
function setUserInfo(name: string, id: number) {
username.value = name;
userId.value = id;
}
function setGameId(id: string) {
gameId.value = id;
}
async function requestState() {
await axios.get(`${api}/status`, {withCredentials: true}).then((response) => {
console.log("STATUS DATA:" + response.data.status + response.data.inGame)
username.value = response.data.username;
if (response.data.gameId) {
console.log("GAMEID:" + response.data.gameId)
gameId.value = response.data.gameId;
}
})
}
function clearUserInfo() {
username.value = null;
userId.value = null;
}
function clearGameId() {
gameId.value = null;
}
return { username, userId, gameId, setUserInfo, requestState, clearUserInfo, setGameId, clearGameId };
});