Wip : Lobby
This commit is contained in:
@@ -3,9 +3,12 @@
|
|||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
await authStore.whoami()
|
await authStore.whoami()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useHead
|
useHead
|
||||||
({
|
({
|
||||||
title
|
title
|
||||||
|
|||||||
+10
-6
@@ -25,16 +25,19 @@ export async function getLobby() {
|
|||||||
|
|
||||||
export async function whoami() {
|
export async function whoami() {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
const req = useFetch<User>(new URL("/whoami", config.public.endpoint).href, {
|
const req = await useFetch<User>(
|
||||||
credentials: "include",
|
new URL("/whoami", config.public.endpoint).href,
|
||||||
});
|
{
|
||||||
|
credentials: "include",
|
||||||
|
}
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
req.error.value?.statusCode &&
|
req.error.value?.statusCode &&
|
||||||
[401].includes(req.error.value.statusCode)
|
[401].includes(req.error.value.statusCode)
|
||||||
) {
|
) {
|
||||||
await navigateTo(config.public.discordLoginEndpoint, {
|
// await navigateTo(config.public.discordLoginEndpoint, {
|
||||||
external: true,
|
// external: true,
|
||||||
});
|
// });
|
||||||
throw new Error("You are not logged in");
|
throw new Error("You are not logged in");
|
||||||
}
|
}
|
||||||
if (req.error.value) {
|
if (req.error.value) {
|
||||||
@@ -42,6 +45,7 @@ export async function whoami() {
|
|||||||
"Something went wrong while trying to get user information"
|
"Something went wrong while trying to get user information"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return req.data;
|
return req.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -9,12 +9,17 @@ const config = useRuntimeConfig()
|
|||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const gameId = route.params.id
|
const gameId = route.params.id
|
||||||
|
|
||||||
const { data: game, pending, error, refresh } = await useFetch<Game>(
|
const { data: game, pending, error, refresh } = (await useFetch<Game>(
|
||||||
new URL(`/games/${gameId}`, config.public.endpoint).href,
|
new URL(`/games/${gameId}`, config.public.endpoint).href,
|
||||||
{
|
{
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
}
|
}
|
||||||
);
|
))
|
||||||
|
// as { data: Ref<Game>, pending: Ref<Boolean>, error: Ref<Error>, refresh: (opts?: unknown | undefined) => Promise<void> }
|
||||||
|
|
||||||
|
if (game.value == null) {
|
||||||
|
throw new Error()
|
||||||
|
}
|
||||||
|
|
||||||
const eventSource = subscribe(`/games/${gameId}/subscribe`)
|
const eventSource = subscribe(`/games/${gameId}/subscribe`)
|
||||||
|
|
||||||
@@ -24,6 +29,7 @@ eventSource.addEventListener("message", (message) => {
|
|||||||
|
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
|
const isSpectator = computed(() => authStore.logged && game.value.teams.every(t => t.players.every(p => p.user.userId !== authStore.selfUser.userId)))
|
||||||
|
|
||||||
// const current_players = computed<Array<Player>>(() => Array.from(goStore.current_game?.players ?? []).filter(p => p.team === goStore.current_game?.current_turn))
|
// const current_players = computed<Array<Player>>(() => Array.from(goStore.current_game?.players ?? []).filter(p => p.team === goStore.current_game?.current_turn))
|
||||||
|
|
||||||
|
|||||||
+7
-3
@@ -8,9 +8,13 @@ export const useAuthStore = defineStore("auth", {
|
|||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
async whoami() {
|
async whoami() {
|
||||||
const data = await whoami();
|
try {
|
||||||
Object.assign(this.selfUser, data.value);
|
const data = await whoami().then((data) => {
|
||||||
this.logged = true;
|
this.logged = true;
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
Object.assign(this.selfUser, data.value);
|
||||||
|
} catch (e) {}
|
||||||
},
|
},
|
||||||
oauth2_register_discord: () => {
|
oauth2_register_discord: () => {
|
||||||
throw Error("not implemented");
|
throw Error("not implemented");
|
||||||
|
|||||||
Reference in New Issue
Block a user