mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
"use server"
|
|
|
|
import axios from "@/lib/axios";
|
|
import { authOptions } from "@/pages/api/auth/[...nextauth]";
|
|
import { getServerSession } from "next-auth";
|
|
import { revalidatePath } from "next/cache";
|
|
|
|
export const editProfileData = async (payload: any) => {
|
|
try {
|
|
const session = await getServerSession(authOptions);
|
|
axios.defaults.headers.common['Authorization'] = `Bearer ${session?.user?.access_token}`;
|
|
|
|
await axios.put('/user/profile/update', payload)
|
|
revalidatePath('profile-data')
|
|
} catch (error: any) {
|
|
console.log("ERROR EDIT PROFILE:", error.response?.data?.code, error.response?.data?.message)
|
|
throw new Error(error as any)
|
|
}
|
|
}
|
|
|
|
export const changeAvatar = 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-avatar', payload)
|
|
revalidatePath('/profile')
|
|
} catch (error) {
|
|
throw new Error(error as any)
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
} |