profi sayfası

This commit is contained in:
2026-01-10 20:38:06 +03:00
parent dd2d7b8379
commit a41da2286f
17 changed files with 476 additions and 93 deletions

View File

@@ -18,7 +18,7 @@ const supabaseAdmin = createSupabaseClient(
}
)
export async function createUser(firstName: string, lastName: string, email: string, password: string, role: 'admin' | 'user') {
export async function createUser(firstName: string, lastName: string, email: string, password: string, role: 'admin' | 'user', phone?: string) {
const supabase = createClient()
// 1. Check if current user is admin
@@ -59,7 +59,8 @@ export async function createUser(firstName: string, lastName: string, email: str
.insert({
id: newUser.user.id,
full_name: `${firstName} ${lastName}`.trim(),
role: role
role: role,
phone: phone
})
if (profileError) {
@@ -91,7 +92,7 @@ export async function deleteUser(userId: string) {
return { success: true }
}
export async function updateUser(userId: string, data: { firstName: string, lastName: string, email: string, password?: string, role: 'admin' | 'user' }) {
export async function updateUser(userId: string, data: { firstName: string, lastName: string, email: string, password?: string, role: 'admin' | 'user', phone?: string }) {
const supabase = createClient()
// Check admin
@@ -107,7 +108,8 @@ export async function updateUser(userId: string, data: { firstName: string, last
.from('profiles')
.update({
full_name: `${data.firstName} ${data.lastName}`.trim(),
role: data.role
role: data.role,
phone: data.phone
})
.eq('id', userId)
@@ -131,3 +133,32 @@ export async function updateUser(userId: string, data: { firstName: string, last
revalidatePath("/dashboard/users")
return { success: true }
}
export async function updateProfile(data: { firstName: string, lastName: string, phone?: string }) {
const supabase = createClient()
const { data: { user } } = await supabase.auth.getUser()
if (!user) return { error: "Oturum açmanız gerekiyor." }
const { error } = await supabase
.from('profiles')
.update({
full_name: `${data.firstName} ${data.lastName}`.trim(),
phone: data.phone
})
.eq('id', user.id)
if (error) return { error: "Profil güncellenemedi: " + error.message }
// Update Auth Metadata as well
if (data.firstName || data.lastName) {
await supabase.auth.updateUser({
data: {
full_name: `${data.firstName} ${data.lastName}`.trim()
}
})
}
revalidatePath("/dashboard/profile")
return { success: true }
}