draupnir4all-web

git clone git://archive.git.mtrnord.blog/MTRNord/draupnir4all-web.git
Log | Files | Refs | README | LICENSE

commit dfb79283f199386e71afbf311a2ca83d648b7448
parent 8e17c300a656a82a01cff2470210834516d8c96f
Author: MTRNord <mtrnord1@gmail.com>
Date:   Mon, 28 Apr 2025 21:03:52 +0200

Fix reload looping

Signed-off-by: MTRNord <mtrnord1@gmail.com>

Diffstat:
Msrc/app/dashboard/analytics/page.tsx | 11++++++++---
Msrc/app/dashboard/bans/page.tsx | 11++++++++---
Msrc/app/dashboard/overview/page.tsx | 17+++++++++--------
Msrc/app/dashboard/page.tsx | 20+++++++++-----------
Msrc/app/dashboard/reports/page.tsx | 11++++++++---
Msrc/app/dashboard/settings/page.tsx | 12++++++++----
6 files changed, 50 insertions(+), 32 deletions(-)

diff --git a/src/app/dashboard/analytics/page.tsx b/src/app/dashboard/analytics/page.tsx @@ -66,9 +66,14 @@ export default function AnalyticsDashboard() { const [selectedTeam, setSelectedTeam] = useState(mockTeams.find((t) => t.id === teamIdParam) || mockTeams[0]) const { user } = useSession() - if (!user) { - redirect("/login") - } + + + useEffect(() => { + // Check if the user is logged in + if (!user) { + redirect("/login") + } + }, [user]) // Update selected team when URL param changes useEffect(() => { diff --git a/src/app/dashboard/bans/page.tsx b/src/app/dashboard/bans/page.tsx @@ -19,9 +19,14 @@ export default function Bans() { const [selectedTeam, setSelectedTeam] = useState(mockTeams.find((t) => t.id === teamIdParam) || mockTeams[0]) const [searchTerm, setSearchTerm] = useState<string>(""); const { user } = useSession() - if (!user) { - redirect("/login") - } + + + useEffect(() => { + // Check if the user is logged in + if (!user) { + redirect("/login") + } + }, [user]) // Update selected team when URL param changes useEffect(() => { diff --git a/src/app/dashboard/overview/page.tsx b/src/app/dashboard/overview/page.tsx @@ -7,16 +7,20 @@ import { mockPolicyLists, mockReports, mockTeams } from "../mockData" import TabNavigation from "../../../components/dashboard/tab-navigation"; import { useSession } from "@/contexts/session-context" import { redirect, useSearchParams } from "next/navigation" - +import { useEffect } from "react" export default function OverviewPage() { const searchParams = useSearchParams() const { user } = useSession() - if (!user) { - redirect("/login") - } - const teamIdParam = searchParams.get("team"); + + useEffect(() => { + // Check if the user is logged in + if (!user) { + redirect("/login") + } + }, [user]) + const selectedTeam = mockTeams.find((t) => t.id === teamIdParam) || mockTeams[0]; const reports = mockReports.filter((report) => report.teamId === selectedTeam.id); const policyLists = mockPolicyLists.filter((list) => list.teamId === selectedTeam.id); @@ -67,9 +71,6 @@ export default function OverviewPage() { <div className="h-3 w-3 rounded-full bg-green-500"></div> <div className="text-sm font-medium">Online</div> </div> - if (!user) { - redirect("/login") - } <p className="text-xs text-gray-400">Last restart: 7d ago</p> </CardContent> </Card> diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx @@ -1,17 +1,14 @@ -"use client" -import { useSession } from "@/contexts/session-context" -import { redirect, useSearchParams } from "next/navigation" +import { redirect } from "next/navigation" -export default function DashboardPage() { - const { user } = useSession() - const searchParams = useSearchParams() - const teamId = searchParams.get("team") - if (!user) { - redirect("/login") - } +export default async function DashboardPage({ + searchParams, +}: { + searchParams: Promise<{ [key: string]: string | string[] | undefined }> +}) { + const teamId = (await searchParams).team as string | undefined // Redirect to overview with team parameter const redirectUrl = teamId ? `/dashboard/overview?team=${teamId}` : "/dashboard/overview" redirect(redirectUrl) -} +} +\ No newline at end of file diff --git a/src/app/dashboard/reports/page.tsx b/src/app/dashboard/reports/page.tsx @@ -27,9 +27,14 @@ export default function ReportsPage() { const teamIdParam = searchParams.get("team") const [selectedTeam, setSelectedTeam] = useState(mockTeams.find((t) => t.id === teamIdParam) || mockTeams[0]) const { user } = useSession() - if (!user) { - redirect("/login") - } + + + useEffect(() => { + // Check if the user is logged in + if (!user) { + redirect("/login") + } + }, [user]) // Update selected team when URL param changes useEffect(() => { diff --git a/src/app/dashboard/settings/page.tsx b/src/app/dashboard/settings/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState } from "react" +import { useEffect, useState } from "react" import { UserPlus, Settings, Trash2, LogOut } from "lucide-react" import { Button } from "@/components/ui/button" @@ -39,9 +39,13 @@ export default function TeamManagement() { const teamIdParam = searchParams.get("team") const [selectedTeam] = useState(mockTeams.find((t) => t.id === teamIdParam) || mockTeams[0]) const { user } = useSession() - if (!user) { - redirect("/login") - } + + useEffect(() => { + // Check if the user is logged in + if (!user) { + redirect("/login") + } + }, [user]) // TODO: Make this actual pages so we can use more ssr const [activeTab, setActiveTab] = useState("members")