import { eq } from "drizzle-orm"; import { redirect } from "next/navigation"; import { connection } from "next/server"; 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 { PasswordForm } from "@/components/auth/password-form"; import { EmailSettings } from "@/components/auth/email-settings"; import { SudlohConnection } from "@/components/auth/sudloh-connection"; import { isAuthorizedAdmin } from "@/lib/auth/authorization"; import { getCustomerSession, isSudlohOidcEnabled } 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, sudloh } = 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 oidcEnabled = isSudlohOidcEnabled(); 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), oidcEnabled ? getDb().select({ providerId: accounts.providerId }) .from(accounts).where(eq(accounts.userId, session.user.id)) : Promise.resolve([]), ]); const [user] = userRows; if (!user) redirect("/auth/login?next=%2Fprofile"); const hasSudloh = accountRows.some((account) => account.providerId === "sudloh"); const hasCredential = accountRows.some((account) => account.providerId === "credential"); return
{isAuthorizedAdmin(session.user) ? : }

โปรไฟล์ของฉัน

{setup === "1" &&

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

}
{oidcEnabled && } {(!hasSudloh || hasCredential) && } {(!hasSudloh || hasCredential) && } {hasSudloh && !hasCredential &&

จัดการอีเมลและรหัสผ่านของคุณผ่าน Sudloh Account

}
; }