"use server" import axios from "@/lib/axios"; import { serverApiCall } from "@/lib/server-api"; import { authOptions } from "@/pages/api/auth/[...nextauth]"; import { getServerSession } from "next-auth"; import { revalidatePath } from "next/cache"; export async function updateProfileAction(payload: any) { const result = await serverApiCall('PUT', '/user/profile/update', payload); if (result.success) { revalidatePath('/profile'); } return result; } export async function changeAvatarAction(nik: string, base64Image: string) { const cleanBase64 = base64Image ? base64Image.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '') : ''; const payload = { nik, avatar: cleanBase64 }; const result = await serverApiCall('POST', '/user/change-avatar', payload); if (result.success) { revalidatePath('/profile'); // Refresh data } return result; } export const changePassword = async (payload: any) => { try { const session = await getServerSession(authOptions); axios.defaults.headers.common['Authorization'] = `Bearer ${session?.user?.access_token}`; await axios.post('/user/profile/change-password', payload) } catch (error) { throw new Error(error as any) } }