Files
Ichsan Kurniawan 7f8e6637e4 Move auth config and build admin menus
Extract NextAuth configuration into a shared library, load admin sidebar items from role permissions, and update related RBAC types and UI.
2026-11-06 18:25:54 +07:00

41 lines
1.2 KiB
TypeScript

"use server"
import { authOptions } from "@/lib/auth";
import axios from "@/lib/axios";
import { serverApiCall } from "@/lib/server-api";
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)
}
}