1- import { useNavigate } from 'react-router' ;
2- import loginApi from '../api/auth/login' ;
3- import getMeApi from '../api/auth/me' ;
4- import signupApi from '../api/auth/signup' ;
5- import socialApi from '../api/auth/social' ;
1+ import loginApi from '@/api/auth/login' ;
2+ import logoutApi from '@/api/auth/logout' ;
3+ import signupApi from '@/api/auth/signup' ;
4+ import socialApi from '@/api/auth/social' ;
5+ import getMeApi from '@/api/users/me' ;
6+ import useAuthStore from '@/hooks/useAuthStore' ;
67import type {
78 LoginRequest ,
89 SignUpRequest ,
910 SocialLoginRequest ,
10- } from '.. /types/auth' ;
11- import useAuthStore from './useAuthStore ' ;
11+ } from '@ /types/auth' ;
12+ import { useNavigate } from 'react-router ' ;
1213
1314export default function useAuth ( ) {
1415 const navigate = useNavigate ( ) ;
@@ -20,7 +21,8 @@ export default function useAuth() {
2021 // 1. μ΄λ©μΌ λ‘κ·ΈμΈ λ‘μ§
2122 const handleLogin = async ( data : LoginRequest ) => {
2223 try {
23- const { user, token } = await loginApi ( data ) ;
24+ const { token } = await loginApi ( data ) ;
25+ const user = await getMeApi ( ) ;
2426 login ( user , token ) ; // Zustand μ€ν μ΄ μ
λ°μ΄νΈ
2527 navigate ( '/' ) ; // λ©μΈ νμ΄μ§λ‘ μ΄λ
2628 } catch ( error ) {
@@ -32,9 +34,8 @@ export default function useAuth() {
3234 // 2. μ΄λ©μΌ νμκ°μ
λ‘μ§
3335 const handleSignUp = async ( data : SignUpRequest ) => {
3436 try {
35- const { user, token } = await signupApi ( data ) ;
36- login ( user , token ) ;
37- navigate ( '/' ) ;
37+ await signupApi ( data ) ;
38+ navigate ( '/login' ) ;
3839 } catch ( error ) {
3940 console . error ( 'Signup failed:' , error ) ;
4041 alert ( 'νμκ°μ
μ€ μ€λ₯κ° λ°μνμ΅λλ€.' ) ;
@@ -44,7 +45,7 @@ export default function useAuth() {
4445 // 3. μμ
λ‘κ·ΈμΈ λ‘μ§
4546 const handleSocialLogin = async ( data : SocialLoginRequest ) => {
4647 try {
47- const { user , token } = await socialApi ( data ) ;
48+ const { token , user } = await socialApi ( data ) ;
4849 login ( user , token ) ;
4950 navigate ( '/' ) ;
5051 } catch ( error ) {
@@ -68,16 +69,12 @@ export default function useAuth() {
6869 } ;
6970
7071 // 5. λ‘κ·Έμμ λ‘μ§
71- const handleLogout = ( ) => {
72+ const handleLogout = async ( ) => {
73+ await logoutApi ( ) ;
7274 logout ( ) ; // Zustand μν μ΄κΈ°ν
7375 navigate ( '/login' ) ;
7476 } ;
7577
76- // 6. κ΄λ¦¬μ νμΈ
77- const isAdmin = ( ownerId : number | undefined ) => {
78- return isLoggedIn && user ?. id === ownerId ;
79- } ;
80-
8178 return {
8279 user,
8380 isLoggedIn,
@@ -86,6 +83,5 @@ export default function useAuth() {
8683 handleSocialLogin,
8784 refreshUser,
8885 handleLogout,
89- isAdmin,
9086 } ;
9187}
0 commit comments