feat: redirect to first channel in list when going to server url

This commit is contained in:
SauceyRed 2025-05-31 16:35:11 +02:00
parent 5011affd49
commit abf3b248c4
Signed by: sauceyred
GPG key ID: 2BF92EB6D8A5CCA7
2 changed files with 18 additions and 2 deletions

15
middleware/server.ts Normal file
View file

@ -0,0 +1,15 @@
import type { ChannelResponse } from "~/types/interfaces";
export default defineNuxtRouteMiddleware(async (to, from) => {
const { fetchChannels } = useApi();
const guildId = to.params.serverId as string;
const channels: ChannelResponse[] | undefined = await fetchChannels(guildId);
console.log("channels:", channels);
if (channels && channels.length > 0) {
console.log("wah");
return await navigateTo(`/servers/${guildId}/channels/${channels[0].uuid}`, { replace: true });
}
})

View file

@ -5,8 +5,9 @@
</template>
<script lang="ts" setup>
const guild = await fetchWithApi(`/guilds/${useRoute().params.serverId}`);
console.log("guild:", guild);
definePageMeta({
middleware: "server"
});
</script>