Block API access when 2FA is required on account; closes #2791

This commit is contained in:
Dane Everitt 2020-12-06 13:56:14 -08:00
parent 5d23d894ae
commit d22456d9ca
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
8 changed files with 101 additions and 40 deletions

View file

@ -0,0 +1,16 @@
import http from '@/api/http';
import { AxiosError } from 'axios';
import { History } from 'history';
export const setupInterceptors = (history: History) => {
http.interceptors.response.use(resp => resp, (error: AxiosError) => {
if (error.response?.status === 400) {
if (error.response?.data.errors?.[0].code === 'TwoFactorAuthRequiredException') {
if (!window.location.pathname.startsWith('/account')) {
history.replace('/account', { twoFactorRedirect: true });
}
}
}
throw error;
});
};