File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,18 @@ authApi.interceptors.request.use((config) => {
1717 return config ;
1818} ) ;
1919
20+ authApi . interceptors . response . use (
21+ ( response ) => response ,
22+ ( error ) => {
23+ if ( error . response ?. status === 401 ) {
24+ localStorage . removeItem ( "token" ) ;
25+ localStorage . removeItem ( "user" ) ;
26+ window . location . href = "/login" ;
27+ }
28+ return Promise . reject ( error ) ;
29+ }
30+ ) ;
31+
2032export const login = async ( username , password ) => {
2133 const response = await authApi . post ( "/login" , { username, password } ) ;
2234 return response . data ;
Original file line number Diff line number Diff line change @@ -23,6 +23,12 @@ api.interceptors.request.use((config) => {
2323api . interceptors . response . use (
2424 ( response ) => response ,
2525 ( error ) => {
26+ if ( error . response ?. status === 401 ) {
27+ localStorage . removeItem ( "token" ) ;
28+ localStorage . removeItem ( "user" ) ;
29+ window . location . href = "/login" ;
30+ return Promise . reject ( error ) ;
31+ }
2632 const message =
2733 error . response ?. data ?. message ||
2834 error . message ||
You can’t perform that action at this time.
0 commit comments