Wip : Lobby
This commit is contained in:
@@ -3,9 +3,12 @@
|
||||
|
||||
const router = useRouter();
|
||||
const authStore = useAuthStore()
|
||||
|
||||
await authStore.whoami()
|
||||
|
||||
|
||||
|
||||
|
||||
useHead
|
||||
({
|
||||
title
|
||||
|
||||
+10
-6
@@ -25,16 +25,19 @@ export async function getLobby() {
|
||||
|
||||
export async function whoami() {
|
||||
const config = useRuntimeConfig();
|
||||
const req = useFetch<User>(new URL("/whoami", config.public.endpoint).href, {
|
||||
credentials: "include",
|
||||
});
|
||||
const req = await useFetch<User>(
|
||||
new URL("/whoami", config.public.endpoint).href,
|
||||
{
|
||||
credentials: "include",
|
||||
}
|
||||
);
|
||||
if (
|
||||
req.error.value?.statusCode &&
|
||||
[401].includes(req.error.value.statusCode)
|
||||
) {
|
||||
await navigateTo(config.public.discordLoginEndpoint, {
|
||||
external: true,
|
||||
});
|
||||
// await navigateTo(config.public.discordLoginEndpoint, {
|
||||
// external: true,
|
||||
// });
|
||||
throw new Error("You are not logged in");
|
||||
}
|
||||
if (req.error.value) {
|
||||
@@ -42,6 +45,7 @@ export async function whoami() {
|
||||
"Something went wrong while trying to get user information"
|
||||
);
|
||||
}
|
||||
|
||||
return req.data;
|
||||
}
|
||||
|
||||
|
||||
+8
-2
@@ -9,12 +9,17 @@ const config = useRuntimeConfig()
|
||||
const route = useRoute()
|
||||
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,
|
||||
{
|
||||
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`)
|
||||
|
||||
@@ -24,6 +29,7 @@ eventSource.addEventListener("message", (message) => {
|
||||
|
||||
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))
|
||||
|
||||
|
||||
+7
-3
@@ -8,9 +8,13 @@ export const useAuthStore = defineStore("auth", {
|
||||
}),
|
||||
actions: {
|
||||
async whoami() {
|
||||
const data = await whoami();
|
||||
Object.assign(this.selfUser, data.value);
|
||||
this.logged = true;
|
||||
try {
|
||||
const data = await whoami().then((data) => {
|
||||
this.logged = true;
|
||||
return data;
|
||||
});
|
||||
Object.assign(this.selfUser, data.value);
|
||||
} catch (e) {}
|
||||
},
|
||||
oauth2_register_discord: () => {
|
||||
throw Error("not implemented");
|
||||
|
||||
Reference in New Issue
Block a user