Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pages/api/dashboard/[id].ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIContext } from 'astro';
import { PermissionFlagsBits } from 'discord.js';
import { ChannelType, PermissionFlagsBits } from 'discord.js';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { getOrCreateDB } = require("../../../utils/functions.js");
Expand Down Expand Up @@ -30,7 +30,7 @@ interface GuildData {
export async function GET(context: APIContext) {
const { params } = context;
const idserver = params.id;
const user = context.locals.user as DiscordUser | undefined;
const user = context.locals?.user as DiscordUser | undefined;

if (!user) {
return new Response('Unauthorized', { status: 401 });
Expand Down
13 changes: 8 additions & 5 deletions src/pages/dashboard/[id].astro
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,20 @@ interface DiscordUser {
const { id } = Astro.params;

// Authentication and data fetching
const user = Astro.locals.user as DiscordUser | undefined;
const user = Astro.locals?.user as DiscordUser | undefined;
if (!user) return Astro.redirect("/api/signin");

let data: GuildData | undefined;
try {
const res = await fetch(`/api/dashboard/${id}`);
if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
const apiUrl = new URL(`/api/dashboard/${id}`, Astro.url);

const res = await fetch(apiUrl);
if (!res.ok) throw new Error(`HTTP ${res.status}`);

data = await res.json();
} catch (error) {
console.error('Fetch error:', error);
return Astro.redirect("/error404"); // Fallback if API fails
console.error("Fetch error:", error);
return Astro.redirect("/error404");
}

const db = data?.db;
Expand Down
Loading