aboutsummaryrefslogtreecommitdiff
path: root/src/app/settings/page.tsx
blob: 1baba3ff9770634a3e8ba8298eff87adbff59bb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { getServerSession } from "next-auth"
import { authOptions } from "@/lib/auth"
import { SettingsForm } from "./settings-form"
import { getUserProfile } from "@/services/user.service"

export default async function SettingsPage() {
  const session = await getServerSession(authOptions)
  
  if (!session?.user?.email) {
    // This case should be handled by middleware, but for type safety:
    return null 
  }

  const user = await getUserProfile(session.user.email)

  if (!user) {
    // This case suggests a data inconsistency (session exists but user not in DB)
    return null
  }

  // Sanitize user object for client component
  const initialUser = {
    name: user.name,
    email: user.email,
    image: user.profileImage?.url || null,
    twoFactorEnabled: !!user.twoFactorEnabled,
  }

  return <SettingsForm user={initialUser} />
}