Skip to content

Commit

Permalink
chore(95): some monitoring of tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
vanch3d committed Sep 18, 2023
1 parent 66af5ad commit 1d50efc
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ export class AxiosHttpRequestWithInterceptors extends BaseHttpRequest {
}
}

const consoleLog = (token: string | undefined, logout = false) => {
console.groupCollapsed(
'%c[dev] Token %c %s %s',
'color:lightblue;font-weight:bold;',
'color:lightcoral;',
token?.slice(-6),
logout ? '(logout)' : ''
)
console.log('Token')
console.log(token)
console.groupEnd()
}

export const useHttpClient = () => {
const { credentials, logout } = useAuth()
const navigate = useNavigate()
Expand All @@ -44,12 +57,15 @@ export const useHttpClient = () => {
// TODO[NVL] Deactivating the reissuing, see https://hivemq.kanbanize.com/ctrl_board/57/cards/15303/details/
// login({ token: reissuedToken }, () => undefined)
}
consoleLog(credentials?.token)

return response
},
function (error: AxiosError) {
// Any status codes that falls outside the range of 2xx cause this function to trigger
// Do something with response error
if (error.response?.status === 401) {
consoleLog(credentials?.token, true)
logout(() => navigate('/login'))
}
return Promise.reject(error)
Expand Down

0 comments on commit 1d50efc

Please sign in to comment.