File tree Expand file tree Collapse file tree 3 files changed +8
-7
lines changed
Expand file tree Collapse file tree 3 files changed +8
-7
lines changed Original file line number Diff line number Diff line change 11"use client" ;
2+ import { HTTPError } from "ky" ;
3+ import { HTTP_STATUS_CODE } from "@/shared/constants/api" ;
24import { useLogout } from "@/app/(auth)/_api/auth.queries" ;
35import { userQueryOptions } from "@/shared/api/queries/user" ;
46import PopupReport from "@/shared/ui/popup/popup-report" ;
@@ -18,8 +20,10 @@ const Setting = () => {
1820 const router = useRouter ( ) ;
1921 const queryClient = useQueryClient ( ) ;
2022 const { data : userInfo } = useQuery ( userQueryOptions . userInfo ( {
21- onError : ( _error ) => {
22- router . replace ( PATH . LOGIN ) ;
23+ onError : ( error ) => {
24+ if ( error instanceof HTTPError && error . response . status === HTTP_STATUS_CODE . UNAUTHORIZED ) {
25+ router . replace ( PATH . LOGIN ) ;
26+ }
2327 } ,
2428 } ) ) ;
2529 const { open } = useOverlay ( ) ;
Original file line number Diff line number Diff line change @@ -22,12 +22,10 @@ const http = ky.create({
2222 async ( error ) => {
2323 if ( error instanceof HTTPError ) {
2424 const { response } = error ;
25- const url = error . request . url ;
26-
27- if ( url . includes ( ENDPOINTS . USER_INFO ) ) {
25+ const pathname = new URL ( error . request . url ) . pathname ;
26+ if ( pathname . endsWith ( ENDPOINTS . USER_INFO ) ) {
2827 return error ;
2928 }
30-
3129 switch ( response . status ) {
3230 case HTTP_STATUS_CODE . UNAUTHORIZED : {
3331 window . location . replace ( PATH . LOGIN ) ;
Original file line number Diff line number Diff line change @@ -18,7 +18,6 @@ export const userQueryOptions = {
1818 queryFn : ( ) => {
1919 return apiClient . get < UserInfo > ( ENDPOINTS . USER_INFO ) ;
2020 } ,
21- onError : options ?. onError ,
2221 ...options ,
2322 } ) ,
2423} ;
You can’t perform that action at this time.
0 commit comments