diff --git a/app/api/channels/[channelId]/route.ts b/app/api/channels/[channelId]/route.ts
index c093f1f..8e3fee5 100644
--- a/app/api/channels/[channelId]/route.ts
+++ b/app/api/channels/[channelId]/route.ts
@@ -49,6 +49,14 @@ export async function PATCH(
return NextResponse.json({ error: "Channel not found" }, { status: 404 });
}
+ // Protect the default channel from changes
+ if (existingChannel.isDefault) {
+ return NextResponse.json(
+ { error: "The default channel cannot be edited." },
+ { status: 400 },
+ );
+ }
+
// Check if the user is a member of the server
const [member] = await db
.select()
@@ -114,6 +122,14 @@ export async function DELETE(
return NextResponse.json({ error: "Channel not found" }, { status: 404 });
}
+ // Protect default channel from deletion
+ if (existingChannel.isDefault) {
+ return NextResponse.json(
+ { error: "The default channel cannot be deleted." },
+ { status: 400 },
+ );
+ }
+
// Check if the user is a member of the server
const [member] = await db
.select()
diff --git a/app/api/servers/route.ts b/app/api/servers/route.ts
index 477b83b..1b39e28 100644
--- a/app/api/servers/route.ts
+++ b/app/api/servers/route.ts
@@ -68,6 +68,7 @@ export async function POST(req: Request) {
.values({
name: "general",
serverId: server.id,
+ isDefault: true,
})
.returning();
diff --git a/components/sidebar/ChannelSidebar.tsx b/components/sidebar/ChannelSidebar.tsx
index dae3d4c..3dedb8e 100644
--- a/components/sidebar/ChannelSidebar.tsx
+++ b/components/sidebar/ChannelSidebar.tsx
@@ -114,15 +114,17 @@ export function ChannelSidebar() {
{/* Gear Button */}
-
+ {!channel.isDefault && (
+
+ )}
);
})}
diff --git a/db/schema.ts b/db/schema.ts
index ef61380..49e2e78 100644
--- a/db/schema.ts
+++ b/db/schema.ts
@@ -5,6 +5,7 @@
import { relations } from "drizzle-orm";
import {
+ boolean,
pgEnum,
pgTable,
text,
@@ -88,6 +89,7 @@ export const channels = pgTable("channels", {
serverId: uuid("server_id")
.references(() => servers.id, { onDelete: "cascade" })
.notNull(),
+ isDefault: boolean("is_default").default(false).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
});