Skip to content

Commit

Permalink
✨ : userData
Browse files Browse the repository at this point in the history
  • Loading branch information
keeprok committed Jan 28, 2025
1 parent 25b14c6 commit 338e3a2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
30 changes: 20 additions & 10 deletions src/features/auth/api/getUserApi.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
// import { axiosInstance } from "@/config/axios"
// interface UserResponse {
// authenticated: boolean
// message: string
// user?: any
// }
import { axiosInstance } from "@/config/axios"

// export const getUserStatus = async (): Promise<UserResponse> => {
// const response = await axiosInstance.get("/Auth/status")
// return response.data
// }
interface UserResponse {
authenticated: boolean
message: string
user: {
email: string
businessName: string
businessNumber: string
businessOwner: string
businessAddress: string
role: string
createdAt: string
updatedAt: string
}
}

export const fetchUserData = async (): Promise<UserResponse> => {
const response = await axiosInstance.get("/Auth/getUsers") // API 호출
return response.data // 응답 데이터 반환
}
7 changes: 7 additions & 0 deletions src/features/auth/components/profile-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import { Columns2 } from "lucide-react"
import { useState } from "react"

import { useUserData } from "../../hook/useAuth"

import { CardLabel } from "./card-label"

export type ProfileMockKeys =
Expand Down Expand Up @@ -39,7 +41,12 @@ export function ProfileCard() {
{ key: "businessName", title: "사업자명" },
{ key: "businessOwner", title: "사업자 대표" },
]
const { data, isLoading, isError } = useUserData()

if (isLoading) return <div>스켈레톤 예정</div>
// 에러 처리
if (isError) return <div>데이터를 불러오는 중 문제가 발생했습니다.</div>
console.log(data)
const toggleSideCard = () => setIsSideCardVisible((prev) => !prev)

return (
Expand Down
14 changes: 13 additions & 1 deletion src/features/auth/hook/useAuth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useMutation } from "@tanstack/react-query"
import { useMutation, useQuery } from "@tanstack/react-query"

import { QUERY_KEYS } from "@/constants/queryKeys"

import type { LoginResponse } from "../api/authApi"
import { postLogin } from "../api/authApi"
import { fetchUserData } from "../api/getUserApi"

export const useAuth = () => {
// 로그인 Mutation
Expand Down Expand Up @@ -47,10 +50,19 @@ export const useAuth = () => {
// console.error("사용자 정보 업데이트 실패:", error)
// },
// })

return {
loginMutation,
// logoutMutation,
// signUpMutation,
// updateUserMutation,
}
}
export const useUserData = () => {
return useQuery({
queryKey: [QUERY_KEYS.AUTH_USER_DATA],
queryFn: fetchUserData,
staleTime: 1000 * 60 * 5, // 5분 동안 캐시 유지
retry: 1, // 실패 시 한 번 재시도})
})
}

0 comments on commit 338e3a2

Please sign in to comment.