Skip to content

Commit

Permalink
fix: team deletion not deleting users and events
Browse files Browse the repository at this point in the history
  • Loading branch information
kcoderhtml committed Apr 22, 2024
1 parent 8512f9f commit 6890763
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/pages/settings.astro
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ if (!session) {
let error = "";
import { db, like, Organization, Event, User } from "astro:db";
if (Astro.request.method === "POST") {
const data = await Astro.request.formData();
if (data.has("updateName") && session.user.role === "admin") {
Expand All @@ -59,12 +61,20 @@ if (Astro.request.method === "POST") {
if (data.has("delete") && session.user.role === "admin") {
await db.delete(Organization).where(like(Organization.team, session.team));
await db.delete(Event).where(like(Event.team, session.team));
await db.delete(User).where(like(User.team, session.team));
return new Response(null, {
status: 302,
headers: new Headers({
Location: "/signout",
}),
});
} else {
error = "You do not have the necessary permissions to delete the team.";
}
}
import { db, like, Organization } from "astro:db";
const team = (
await db
.select()
Expand Down
39 changes: 39 additions & 0 deletions src/pages/signout.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
import Base from "../Layouts/Base.astro";
import { getSession } from "auth-astro/server";
import { type Session } from "@auth/core/types";
type ExtendedSession = {
team: string;
teamName: string;
teamImage: string;
user: {
role: string;
};
};
const session = (await getSession(Astro.request)) as Session & ExtendedSession;
if (!session) {
return new Response(null, {
status: 302,
headers: new Headers({
Location: "/",
}),
});
}
---

<Base title="Sign Out">
<div class="flex items-center justify-center h-screen">
<div class="text-center">
<h1 class="text-3xl font-bold">Signing out...</h1>
</div>
</div>
</Base>

<script>
import { signOut } from "auth-astro/client";
await signOut();
</script>

0 comments on commit 6890763

Please sign in to comment.