Block API access when 2FA is required on account; closes #2791
This commit is contained in:
parent
5d23d894ae
commit
d22456d9ca
8 changed files with 101 additions and 40 deletions
16
resources/scripts/api/interceptors.ts
Normal file
16
resources/scripts/api/interceptors.ts
Normal 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;
|
||||
});
|
||||
};
|
Reference in a new issue