feat: add getProfile function and integrate user profile retrieval in payment and layout components
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m47s

This commit is contained in:
2025-04-20 07:40:31 +05:00
parent ac11fee754
commit ba91d2c8d4
5 changed files with 51 additions and 18 deletions

View File

@ -4,6 +4,7 @@ import { Wallet } from "@/components/wallet";
import { ModeToggle } from "@/components/theme-toggle";
import { AppSidebar } from "@/components/ui/app-sidebar";
import { getProfile } from "@/actions/payment";
import { authOptions } from "@/app/auth";
import { Separator } from "@/components/ui/separator";
import {
@ -11,6 +12,7 @@ import {
SidebarProvider,
SidebarTrigger,
} from "@/components/ui/sidebar";
import { tryCatch } from "@/utils/tryCatch";
import { getServerSession } from "next-auth";
import { redirect } from "next/navigation";
import { AccountPopover } from "./account-popver";
@ -21,6 +23,11 @@ export async function ApplicationLayout({
const session = await getServerSession(authOptions);
if (!session) return redirect("/auth/signin");
const [userError, userProfile] = await tryCatch(getProfile());
if (userError) {
if (userError.message === "Invalid token.") redirect("/auth/signin");
return null;
}
return (
<SidebarProvider>
<AppSidebar />
@ -30,7 +37,7 @@ export async function ApplicationLayout({
<div className="flex items-center gap-2 ">
<SidebarTrigger className="-ml-1" />
<Separator orientation="vertical" className="mr-2 h-4" />
<div className="text-sm font-mono px-2 p-1 rounded-md bg-green-500/10 text-green-900 dark:text-green-400">
<div className="text-xs font-mono px-2 p-1 rounded-md bg-green-500/10 text-green-900 dark:text-green-400">
Welcome,{" "}
<span className="font-semibold">
{session?.user?.first_name} {session?.user?.last_name}
@ -39,7 +46,7 @@ export async function ApplicationLayout({
</div>
<div className="flex items-center gap-2">
<Wallet walletBalance={session?.user?.wallet_balance || 0} />
<Wallet walletBalance={userProfile?.wallet_balance || 0} />
<ModeToggle />
<AccountPopover />
</div>