File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 11import { clientConfig } from '@/lib/config/clientConfig'
22import { APIError , NetworkError } from '@/lib/utils'
33import { isValidMongoObjectId } from '@/lib/validation'
4- import { API_ENDPOINTS } from '@/constants'
4+ import { API_ENDPOINTS , STORAGE_KEYS } from '@/constants'
55
66interface APIClientConfig {
77 baseURL : string
@@ -222,6 +222,7 @@ class APIClient {
222222 errorData
223223 )
224224 } else {
225+ this . clearStoredUser ( )
225226 if ( typeof window !== 'undefined' ) {
226227 window . location . href = '/login'
227228 }
@@ -312,9 +313,11 @@ class APIClient {
312313 if ( refreshResponse . ok ) {
313314 return true
314315 } else {
316+ this . clearStoredUser ( )
315317 return false
316318 }
317319 } catch {
320+ this . clearStoredUser ( )
318321 return false
319322 } finally {
320323 this . isRefreshing = false
@@ -325,6 +328,19 @@ class APIClient {
325328 return await this . refreshPromise
326329 }
327330
331+ private clearStoredUser ( ) {
332+ if ( typeof window === 'undefined' ) {
333+ return
334+ }
335+
336+ try {
337+ localStorage . removeItem ( STORAGE_KEYS . USER_ID )
338+ localStorage . removeItem ( STORAGE_KEYS . USER_EMAIL )
339+ } catch ( error ) {
340+ console . warn ( 'Failed to clear auth storage:' , error )
341+ }
342+ }
343+
328344 private combineAbortSignals ( signals : AbortSignal [ ] ) : AbortSignal {
329345 const controller = new AbortController ( )
330346
You can’t perform that action at this time.
0 commit comments