feat:menambahkan fitur superadmin
This commit is contained in:
+19
-1
@@ -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", [])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user