mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 20:06:28 +00:00
5cbded392a
Introduce a reusable serverApiCall helper and file-based logger (lib/server-api.ts, lib/logger.ts) to centralize backend requests, attach session auth, and capture request/response/error logs. Update server actions to use the new helper (updateProfileAction, changeAvatarAction) and ensure profile revalidation. Add client-side avatar upload size limit (5MB) and normalize avatar base64 payload. Add new OpenGraph/Twitter images, bump app version to v1.1.1, and add a v1.1.1 entry in release notes. Update default API/IMG env URLs and metadataBase fallback, fix minor release-notes link capitalization, and adjust a debug console.log in admin user page.
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
"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)
|
|
}
|
|
} |