import { eq, sql } from "drizzle-orm"; import { redirect } from "next/navigation"; import { connection } from "next/server"; import { UserRoundIcon } from "lucide-react"; import { getDb } from "@/db"; import { accounts, users } from "@/db/schema"; import { SiteHeader } from "@/components/public/site-header"; import { AdminHeader } from "@/components/admin/admin-header"; import { ProfileForm } from "@/components/auth/profile-form"; import { GoogleAccountSettings } from "@/components/auth/google-account-settings"; import { PasswordForm } from "@/components/auth/password-form"; import { EmailSettings } from "@/components/auth/email-settings"; import { isAuthorizedAdmin } from "@/lib/auth/authorization"; import { getCustomerSession, isGoogleAuthEnabled } from "@/lib/auth/server"; import { safeAuthReturnPath } from "@/lib/auth/return-path"; export const instant = false; export default async function ProfilePage({ searchParams }: PageProps<"/profile">) { await connection(); const { setup, next, upload, emailAction, error, googleLinkError } = await searchParams; const nextPath = safeAuthReturnPath(next); const setupNextPath = nextPath === "/profile" || nextPath.startsWith("/profile?") ? "/" : nextPath; const session = await getCustomerSession(); if (!session) redirect("/auth/login?next=%2Fprofile"); const [userRows, accountRows] = await Promise.all([ getDb().select({ name: users.name, email: users.email, emailVerified: users.emailVerified, image: users.image }) .from(users).where(eq(users.id, session.user.id)).limit(1), getDb().select({ id: accounts.id, providerId: accounts.providerId, hasPassword: sql`${accounts.password} is not null` }) .from(accounts).where(eq(accounts.userId, session.user.id)), ]); const [user] = userRows; if (!user) redirect("/auth/login?next=%2Fprofile"); const hasPassword = accountRows.some((account) => account.providerId === "credential" && account.hasPassword); const googleAccountIds = accountRows.filter((account) => account.providerId === "google") .map((account) => account.id); const hasOtherAuthMethod = accountRows.some((account) => account.providerId !== "google" && (account.providerId !== "credential" || account.hasPassword)); return
{isAuthorizedAdmin(session.user) ? : }

{setup === "1" &&

{upload === "failed" ? "สร้างบัญชีแล้ว แต่บันทึกรูปโปรไฟล์ไม่สำเร็จ กรุณาลองอีกครั้ง" : "สร้างบัญชีเรียบร้อยแล้ว เพิ่มรูปโปรไฟล์ได้ตามต้องการ หรือกดข้ามเพื่อเริ่มใช้งาน"}

}
{isGoogleAuthEnabled() && }
; }