Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
students
survey
Commits
e6f3e052
You need to sign in or sign up before continuing.
Commit
e6f3e052
authored
Nov 15, 2022
by
Yoon, Daeki
😅
Browse files
api error 발생을 axios interceptor 이용 처리함
parent
8d00247e
Changes
2
Hide whitespace changes
Inline
Side-by-side
frontend/src/apis/useAxiosInterceptor.ts
0 → 100644
View file @
e6f3e052
import
{
useEffect
}
from
"
react
"
;
import
{
NavigateFunction
,
useLocation
}
from
"
react-router-dom
"
;
import
customAxios
from
"
./axios.config
"
;
export
const
useAxiosInterceptor
=
(
navigate
:
NavigateFunction
)
=>
{
const
location
=
useLocation
();
useEffect
(()
=>
{
const
responseInterceptor
=
customAxios
.
interceptors
.
response
.
use
(
(
response
)
=>
response
,
(
error
)
=>
{
if
(
error
.
response
.
status
===
401
)
{
navigate
(
"
/login
"
,
{
replace
:
true
,
state
:
{
from
:
location
.
pathname
},
});
}
return
Promise
.
reject
(
error
);
}
);
return
()
=>
{
customAxios
.
interceptors
.
response
.
eject
(
responseInterceptor
);
};
},
[]);
};
frontend/src/layouts/BaseLayout.tsx
View file @
e6f3e052
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
{
Outlet
}
from
"
react-router-dom
"
;
import
{
Outlet
,
useNavigate
}
from
"
react-router-dom
"
;
import
{
useAxiosInterceptor
}
from
"
../apis
"
;
import
{
AuthProvider
}
from
"
../auth
"
;
import
{
AuthProvider
}
from
"
../auth
"
;
import
{
Header
}
from
"
../commons
"
;
import
{
Header
}
from
"
../commons
"
;
export
const
BaseLayout
=
()
=>
{
export
const
BaseLayout
=
()
=>
{
const
navigate
=
useNavigate
();
useAxiosInterceptor
(
navigate
);
return
(
return
(
<
AuthProvider
>
<
AuthProvider
>
<
Header
/>
<
Header
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment