Feat: Fetch user email in Edit User page

This commit is contained in:
2025-12-03 22:56:25 +03:00
parent e61abe0189
commit 03b9423ceb

View File

@@ -1,10 +1,12 @@
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { EditUserForm } from "./edit-user-form"
import { createClient } from "@/lib/supabase/server"
import { createAdminClient } from "@/lib/supabase/admin"
import { notFound } from "next/navigation"
export default async function EditUserPage({ params }: { params: { id: string } }) {
const supabase = await createClient()
const supabaseAdmin = await createAdminClient()
// Fetch profile
const { data: profile } = await supabase
@@ -17,8 +19,14 @@ export default async function EditUserPage({ params }: { params: { id: string }
notFound()
}
// We can't easily get email from profiles if it's not stored there.
// But for editing, we mostly care about name and role.
// Fetch email from auth.users using admin client
let email = undefined
if (supabaseAdmin) {
const { data: { user }, error } = await supabaseAdmin.auth.admin.getUserById(params.id)
if (user) {
email = user.email
}
}
return (
<div className="max-w-2xl mx-auto">
@@ -31,7 +39,7 @@ export default async function EditUserPage({ params }: { params: { id: string }
id: profile.id,
full_name: profile.full_name,
role: profile.role,
email: undefined // Email is not in profiles table currently
email: email
}} />
</CardContent>
</Card>