feat:menambahkan fitur superadmin

This commit is contained in:
2026-05-15 00:25:37 +07:00
parent 71388d2df7
commit e359365139
8 changed files with 358 additions and 23 deletions
+19 -1
View File
@@ -31,7 +31,14 @@ export function getCurrentUser() {
export function setAuth({ token, user }) {
localStorage.setItem("secondtech_token", token)
setLocal("secondtech_user", user)
setLocal("secondtech_user", {
id: user.id,
name: user.name,
email: user.email,
whatsapp: user.whatsapp,
role: user.role || "user"
})
}
export function clearAuth() {
@@ -56,6 +63,7 @@ async function requestJson(path, options = {}) {
...options,
headers
})
const data = await response.json().catch(() => ({}))
if (!response.ok) {
@@ -79,6 +87,10 @@ export function loginUser(payload) {
})
}
export function fetchCurrentUser() {
return requestJson("/api/auth/me")
}
export function fetchProducts() {
return requestJson("/api/products")
}
@@ -111,6 +123,12 @@ export function deleteProductById(id) {
})
}
export function deleteProductAsAdmin(id) {
return requestJson(`/api/admin/products/${id}`, {
method: "DELETE"
})
}
export function getSavedProducts() {
return getLocal("secondtech_saved", [])
}