File tree 8 files changed +19
-29
lines changed
8 files changed +19
-29
lines changed Original file line number Diff line number Diff line change 1
- import { isLoginState } from 'atom/recoilStore' ;
2
1
import { RouterProvider } from 'react-router' ;
3
- import type { MutableSnapshot } from 'recoil' ;
4
- import { RecoilRoot } from 'recoil' ;
5
- import { getAccessToken } from 'utils/tokenManager' ;
6
2
7
3
import { router } from './__generated__/routes.generated' ;
8
4
9
5
const App = ( ) => {
10
- const initialState = ( { set } : MutableSnapshot ) => {
11
- const isLogin = ! ! getAccessToken ( ) ;
12
- set ( isLoginState , isLogin || false ) ;
13
- } ;
14
-
15
- return (
16
- < RecoilRoot initializeState = { initialState } >
17
- < RouterProvider router = { router } />
18
- </ RecoilRoot >
19
- ) ;
6
+ return < RouterProvider router = { router } /> ;
20
7
} ;
21
8
22
9
export default App ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -2,10 +2,10 @@ import axios from 'axios';
2
2
import { TOKEN_KEY } from 'constants/auth' ;
3
3
import jwtDecode , { type JwtPayload } from 'jwt-decode' ;
4
4
import { useEffect } from 'react' ;
5
+ import { useAuthStore } from 'stores/authStore' ;
5
6
import { getAccessToken , setToken } from 'utils/tokenManager' ;
6
7
7
8
import { logout , refresh } from '../api/etc' ;
8
- import useUserStore from './useUserStore' ;
9
9
10
10
const PROXY_URL = window . location . hostname === 'localhost' ? '/api' : '/proxy' ;
11
11
@@ -15,7 +15,7 @@ const http = axios.create({
15
15
} ) ;
16
16
17
17
const useHttp = ( ) => {
18
- const { isLogin } = useUserStore ( ) ;
18
+ const { isLogin } = useAuthStore ( ) ;
19
19
20
20
//액세스토큰 유효성 검사
21
21
const isAccessTokenValid = async ( ) => {
Original file line number Diff line number Diff line change 1
1
import { useMutation , useQueryClient } from '@tanstack/react-query' ;
2
2
import { login as loginApi , refresh as refreshApi } from 'api/Auth' ;
3
- import { isLoginState } from 'atom/recoilStore' ;
4
3
import type { AxiosError } from 'axios' ;
5
4
import { REFRESH_KEY , TOKEN_KEY } from 'constants/auth' ;
6
5
import { useLocation } from 'react-router' ;
7
- import { useRecoilState } from 'recoil ' ;
6
+ import { useAuthStore } from 'stores/authStore ' ;
8
7
import type { APIErrorResponse } from 'types/common' ;
9
8
import type { UserLogin } from 'types/user' ;
10
9
import { removeTokenAll , setToken } from 'utils/tokenManager' ;
@@ -13,12 +12,10 @@ import useRouter from './useRouter';
13
12
14
13
const useUserStore = ( ) => {
15
14
const queryClient = useQueryClient ( ) ;
16
-
15
+ const { isLogin , setIsLogin } = useAuthStore ( ) ;
17
16
const { push } = useRouter ( ) ;
18
17
const { state } = useLocation ( ) ;
19
18
20
- const [ isLogin , setIsLogin ] = useRecoilState ( isLoginState ) ;
21
-
22
19
const { mutateAsync : login } = useMutation ( {
23
20
mutationFn : ( formData : UserLogin ) => loginApi ( formData ) ,
24
21
onSuccess : ( data ) => {
Original file line number Diff line number Diff line change
1
+ import { getAccessToken } from 'utils/tokenManager' ;
2
+ import { create } from 'zustand' ;
3
+
4
+ interface AuthState {
5
+ isLogin : boolean ;
6
+ setIsLogin : ( value : boolean ) => void ;
7
+ }
8
+
9
+ export const useAuthStore = create < AuthState > ( ( set ) => ( {
10
+ isLogin : ! ! getAccessToken ( ) ,
11
+ setIsLogin : ( isLogin : boolean ) => set ( { isLogin } ) ,
12
+ } ) ) ;
Original file line number Diff line number Diff line change 19
19
"paths" : {
20
20
"*" : [" *" ],
21
21
"api/*" : [" api/*" ],
22
- "atom/*" : [" atom/*" ],
23
22
"constants/*" : [" constants/*" ],
24
23
"components/*" : [" components/*" ],
25
24
"hooks/*" : [" hooks/*" ],
26
25
"pages/*" : [" pages/*" ],
26
+ "stores/*" : [" stores/*" ],
27
27
"styles/*" : [" styles/*" ],
28
28
"types/*" : [" types/*" ],
29
29
"utils/*" : [" utils/*" ]
Original file line number Diff line number Diff line change @@ -17,11 +17,11 @@ export default defineConfig({
17
17
resolve : {
18
18
alias : {
19
19
api : '/src/api' ,
20
- atom : '/src/atom' ,
21
20
constants : '/src/constants' ,
22
21
components : '/src/components' ,
23
22
hooks : '/src/hooks' ,
24
23
pages : '/src/pages' ,
24
+ stores : '/src/stores' ,
25
25
styles : '/src/styles' ,
26
26
types : '/src/types' ,
27
27
utils : '/src/utils' ,
You can’t perform that action at this time.
0 commit comments