Skip to content

Commit

Permalink
feat:#345 api 요청 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dalzzy committed Feb 7, 2025
1 parent 2912d43 commit 2992595
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/api/getAdminUser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useEffect, useState } from 'react';
import axios from 'axios';

const BASE_URL = import.meta.env.VITE_API_URL;

export const getAllUsers = async () => {
const accessToken = localStorage.getItem('accessToken');
const refreshToken = localStorage.getItem('refreshToken');

return axios.get(`${BASE_URL}/api/v1/admin/users/all`, {
headers: {
Authorization: `Bearer ${accessToken}`,
Authorization_refresh: `Bearer ${refreshToken}`,
},
});
};

export const useGetAllUsers = () => {
const [allUsers, setAllUsers] = useState<any[]>([]);
const [error, setError] = useState<string | null>(null);

useEffect(() => {
const fetchUsers = async () => {
try {
const response = await getAllUsers();
setAllUsers(response.data.data);
setError(null);
} catch (err: any) {
setError(err.response?.data?.message);
}
};

fetchUsers();
}, []);

return { allUsers, error };
};

export default useGetAllUsers;

0 comments on commit 2992595

Please sign in to comment.