|
|
@@ -1,7 +1,7 @@
|
|
|
import { create } from 'zustand'
|
|
|
import { persist } from 'zustand/middleware'
|
|
|
import type { AdminUser, LoginResponse } from '@/types/auth'
|
|
|
-import api from '@/lib/axios'
|
|
|
+import { http } from '@/core/api/http'
|
|
|
|
|
|
interface LoginPayload {
|
|
|
username: string
|
|
|
@@ -28,17 +28,16 @@ export const useAuthStore = create<AuthState>()(
|
|
|
loading: false,
|
|
|
error: null,
|
|
|
|
|
|
- /* -------------------------- LOGIN -------------------------- */
|
|
|
login: async (data: LoginPayload) => {
|
|
|
set({ loading: true, error: null })
|
|
|
|
|
|
try {
|
|
|
- const response = await api.post<LoginResponse>(
|
|
|
+ const response = await http.post<LoginResponse>(
|
|
|
'/admin/auth/login',
|
|
|
data
|
|
|
)
|
|
|
|
|
|
- const { token, admin } = response.data.data
|
|
|
+ const { token, admin } = response.data
|
|
|
|
|
|
set({
|
|
|
token,
|
|
|
@@ -61,7 +60,6 @@ export const useAuthStore = create<AuthState>()(
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- /* -------------------------- LOGOUT -------------------------- */
|
|
|
logout: () => {
|
|
|
set({
|
|
|
user: null,
|
|
|
@@ -71,13 +69,12 @@ export const useAuthStore = create<AuthState>()(
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- /* ----------------------- FETCH PROFILE ---------------------- */
|
|
|
fetchProfile: async () => {
|
|
|
try {
|
|
|
- const res = await api.get<{ data: AdminUser }>('/admin/auth/profile')
|
|
|
+ const res = await http.get<{ data: AdminUser }>('/admin/auth/profile')
|
|
|
|
|
|
set({
|
|
|
- user: res.data.data,
|
|
|
+ user: res.data,
|
|
|
isAuthenticated: true,
|
|
|
})
|
|
|
} catch (error) {
|
|
|
@@ -89,7 +86,6 @@ export const useAuthStore = create<AuthState>()(
|
|
|
{
|
|
|
name: 'auth-storage',
|
|
|
|
|
|
- // فقط اطلاعات لازم persist شود
|
|
|
partialize: (state) => ({
|
|
|
user: state.user,
|
|
|
token: state.token,
|