diff --git a/app/(user)/dashboard/page.tsx b/app/(user)/dashboard/page.tsx
index e0a5a31..464712c 100644
--- a/app/(user)/dashboard/page.tsx
+++ b/app/(user)/dashboard/page.tsx
@@ -1,29 +1,17 @@
import { redirect } from "next/navigation";
-import { createClient } from "../../lib/supabase/server";
import DashboardWithoutKey from "../../components/dashboard/WithoutKey";
import Stats from "@/app/components/dashboard/Stats";
import { Metadata } from "next";
+import { getUserWithProfile } from "@/app/lib/supabase/help/user";
export const metadata: Metadata = {
title: "Dashboard - DevPulse",
- description: "Monitor your coding activity and manage your leaderboards.",
};
export default async function Dashboard() {
- const supabase = await createClient();
-
- const {
- data: { user },
- } = await supabase.auth.getUser();
-
+ const { user, profile } = await getUserWithProfile();
if (!user) redirect("/login");
- const { data: profile } = await supabase
- .from("profiles")
- .select("wakatime_api_key, email")
- .eq("id", user.id)
- .single();
-
if (!profile?.wakatime_api_key) {
return
;
}
diff --git a/app/(user)/dashboard/settings/page.tsx b/app/(user)/dashboard/settings/page.tsx
index a640b6c..e8c6262 100644
--- a/app/(user)/dashboard/settings/page.tsx
+++ b/app/(user)/dashboard/settings/page.tsx
@@ -1,18 +1,16 @@
import { Metadata } from "next";
-import { createClient } from "../../../lib/supabase/server";
import UserProfile from "@/app/components/dashboard/Settings/Profile";
import ResetPassword from "@/app/components/dashboard/Settings/ResetPassword";
+import { getUserWithProfile } from "@/app/lib/supabase/help/user";
+import { redirect } from "next/navigation";
export const metadata: Metadata = {
title: "Settings - DevPulse",
- description:
- "Manage your account settings and including your WakaTime API key.",
};
export default async function LeaderboardsPage() {
- const supabase = await createClient();
- const { data: userData } = await supabase.auth.getUser();
- const user = userData.user;
+ const { user } = await getUserWithProfile();
+ if (!user) return redirect("/login?from=/dashboard/settings");
return (
diff --git a/app/(user)/update-password/page.tsx b/app/(user)/update-password/page.tsx
index 7856d39..e63c719 100644
--- a/app/(user)/update-password/page.tsx
+++ b/app/(user)/update-password/page.tsx
@@ -5,7 +5,6 @@ import Footer from "@/app/components/layout/Footer";
export const metadata: Metadata = {
title: "Update Password - DevPulse",
- description: "Update your DevPulse password to keep your account secure.",
};
export default async function UpdatePassword() {
diff --git a/app/api/wakatime/sync/route.ts b/app/api/wakatime/sync/route.ts
index ed1dda7..680c492 100644
--- a/app/api/wakatime/sync/route.ts
+++ b/app/api/wakatime/sync/route.ts
@@ -1,8 +1,10 @@
import { NextResponse } from "next/server";
import { createClient } from "../../../lib/supabase/server";
+import { getUserWithProfile } from "@/app/lib/supabase/help/user";
export async function GET(request: Request) {
const supabase = await createClient();
+ const { user, profile } = await getUserWithProfile();
const { searchParams } = new URL(request.url);
const apiKey = searchParams.get("apiKey") || "";
let profile$: { wakatime_api_key: string };
@@ -16,22 +18,11 @@ export async function GET(request: Request) {
profile$ = { wakatime_api_key: apiKey };
- const {
- data: { user },
- } = await supabase.auth.getUser();
-
if (!user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
if (!apiKey) {
- // Get profile with API key
- const { data: profile } = await supabase
- .from("profiles")
- .select("wakatime_api_key")
- .eq("id", user.id)
- .single();
-
if (!profile?.wakatime_api_key) {
return NextResponse.json({ error: "No API key found" }, { status: 400 });
}
@@ -80,7 +71,7 @@ export async function GET(request: Request) {
`https://wakatime.com/api/v1/users/current/summaries?start=${startStr}&end=${endStr}`,
{
headers: { Authorization: authHeader },
- }
+ },
),
]);
@@ -129,34 +120,38 @@ export async function GET(request: Request) {
}
}
- const { data: statsResult, error: statsError } = await supabase
- .from("user_stats")
- .upsert({
- user_id: user.id,
- total_seconds: Math.floor(wakaStats.total_seconds),
- daily_average: Math.floor(wakaStats.daily_average || 0),
- languages: wakaStats.languages,
- operating_systems: wakaStats.operating_systems,
- editors: wakaStats.editors,
- machines: wakaStats.machines,
- categories: wakaStats.categories,
- dependencies: wakaStats.dependencies || [],
- best_day: wakaStats.best_day || {},
- daily_stats: daily_stats,
- last_fetched_at: new Date().toISOString(),
- })
- .select()
- .single();
-
- const { data: projectsResult, error: projectsError } = await supabase
- .from("user_projects")
- .upsert({
- user_id: user.id,
- projects: wakaStats.projects,
- last_fetched_at: new Date().toISOString(),
- })
- .select()
- .single();
+ const [
+ { data: statsResult, error: statsError },
+ { data: projectsResult, error: projectsError },
+ ] = await Promise.all([
+ supabase
+ .from("user_stats")
+ .upsert({
+ user_id: user.id,
+ total_seconds: Math.floor(wakaStats.total_seconds),
+ daily_average: Math.floor(wakaStats.daily_average || 0),
+ languages: wakaStats.languages,
+ operating_systems: wakaStats.operating_systems,
+ editors: wakaStats.editors,
+ machines: wakaStats.machines,
+ categories: wakaStats.categories,
+ dependencies: wakaStats.dependencies || [],
+ best_day: wakaStats.best_day || {},
+ daily_stats: daily_stats,
+ last_fetched_at: new Date().toISOString(),
+ })
+ .select()
+ .single(),
+ supabase
+ .from("user_projects")
+ .upsert({
+ user_id: user.id,
+ projects: wakaStats.projects,
+ last_fetched_at: new Date().toISOString(),
+ })
+ .select()
+ .single(),
+ ]);
const mergedResult = {
...statsResult,
diff --git a/app/components/Chat.tsx b/app/components/Chat.tsx
index 601cdc0..9d620c1 100644
--- a/app/components/Chat.tsx
+++ b/app/components/Chat.tsx
@@ -666,6 +666,13 @@ export default function Chat({ user }: { user: User }) {
placeholder="Search user..."
className="w-full mb-3 px-3 py-2 bg-transparent text-gray-100 placeholder:text-gray-500 border border-neutral-800 rounded-xl outline-none"
/>
+
+ {allUsers.length == 0 && (
+
+ )}
+
{allUsers
.filter((u) =>
diff --git a/app/components/dashboard/WithoutKey.tsx b/app/components/dashboard/WithoutKey.tsx
index 4fdf5c3..75a63a8 100644
--- a/app/components/dashboard/WithoutKey.tsx
+++ b/app/components/dashboard/WithoutKey.tsx
@@ -53,7 +53,7 @@ export default function DashboardWithoutKey({ email }: { email: string }) {
};
return (
-
+
Connect Wakatime
@@ -62,7 +62,7 @@ export default function DashboardWithoutKey({ email }: { email: string }) {
-
+
Welcome {email}. Enter
your WakaTime API key to activate your DevPulse dashboard.
diff --git a/app/lib/supabase/help/user.ts b/app/lib/supabase/help/user.ts
new file mode 100644
index 0000000..58fe3b1
--- /dev/null
+++ b/app/lib/supabase/help/user.ts
@@ -0,0 +1,20 @@
+import { cache } from "react";
+import { createClient } from "../server";
+
+export const getUserWithProfile = cache(async () => {
+ const supabase = await createClient();
+
+ const {
+ data: { user },
+ } = await supabase.auth.getUser();
+
+ if (!user) return { user: null, profile: null };
+
+ const { data: profile } = await supabase
+ .from("profiles")
+ .select("wakatime_api_key, email, role")
+ .eq("id", user.id)
+ .single();
+
+ return { user, profile };
+});