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