mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-03 12:08:31 +00:00
Merge pull request #38 from open-metadata/issue-37
Added intercepter for 403
This commit is contained in:
commit
4cfe6a419a
@ -30,6 +30,7 @@ import React, {
|
||||
import { Callback, makeAuthenticator, makeUserManager } from 'react-oidc';
|
||||
import { Redirect, Route, Switch, useHistory } from 'react-router-dom';
|
||||
import appState from '../AppState';
|
||||
import axiosClient from '../axiosAPIs';
|
||||
import { fetchAuthorizerConfig } from '../axiosAPIs/miscAPI';
|
||||
import {
|
||||
getLoggedInUser,
|
||||
@ -38,7 +39,9 @@ import {
|
||||
getUsers,
|
||||
} from '../axiosAPIs/userAPI';
|
||||
import { oidcTokenKey, ROUTES, TIMEOUT } from '../constants/constants';
|
||||
import { ClientErrors } from '../enums/axios.enum';
|
||||
import { useAuth } from '../hooks/authHooks';
|
||||
import useToastContext from '../hooks/useToastContext';
|
||||
import SigninPage from '../pages/login';
|
||||
import PageNotFound from '../pages/page-not-found';
|
||||
import {
|
||||
@ -65,6 +68,7 @@ const AuthProvider: FunctionComponent<AuthProviderProps> = ({
|
||||
children,
|
||||
}: AuthProviderProps) => {
|
||||
const history = useHistory();
|
||||
const showToast = useToastContext();
|
||||
const { isSignedIn, isSigningIn, isSignedOut } = useAuth();
|
||||
|
||||
const oidcUserToken = cookieStorage.getItem(oidcTokenKey);
|
||||
@ -190,6 +194,24 @@ const AuthProvider: FunctionComponent<AuthProviderProps> = ({
|
||||
|
||||
useEffect(() => {
|
||||
fetchAuthConfig();
|
||||
|
||||
// Axios intercepter for statusCode 403
|
||||
axiosClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (error.response) {
|
||||
const { status } = error.response;
|
||||
if (status === ClientErrors.FORBIDDEN) {
|
||||
showToast({
|
||||
variant: 'error',
|
||||
body: 'You do not have permission for this action!',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@ -18,10 +18,10 @@
|
||||
import axios from 'axios';
|
||||
import { CookieStorage } from 'cookie-storage';
|
||||
import { oidcTokenKey } from '../constants/constants';
|
||||
import { ClientErrors } from '../enums/axios.enum';
|
||||
import { userSignOut } from '../utils/AuthUtils';
|
||||
|
||||
const cookieStorage = new CookieStorage();
|
||||
const UNAUTHORIZED = 401;
|
||||
|
||||
const axiosClient = axios.create({
|
||||
baseURL: '/api/v1',
|
||||
@ -41,7 +41,7 @@ axiosClient.interceptors.response.use(
|
||||
(error) => {
|
||||
if (error.response) {
|
||||
const { status } = error.response;
|
||||
if (status === UNAUTHORIZED) {
|
||||
if (status === ClientErrors.UNAUTHORIZED) {
|
||||
userSignOut();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
export enum ClientErrors {
|
||||
BAD_REQUEST = 400,
|
||||
UNAUTHORIZED = 401,
|
||||
PAYMENT_REQUIRED = 402,
|
||||
FORBIDDEN = 403,
|
||||
NOT_FOUND = 404,
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user