mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-18 14:23:44 +02:00
Block API access when 2FA is required on account; closes #2791
This commit is contained in:
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 New Issue
Block a user