mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-13 17:32:53 +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 { Callback, makeAuthenticator, makeUserManager } from 'react-oidc';
|
||||||
import { Redirect, Route, Switch, useHistory } from 'react-router-dom';
|
import { Redirect, Route, Switch, useHistory } from 'react-router-dom';
|
||||||
import appState from '../AppState';
|
import appState from '../AppState';
|
||||||
|
import axiosClient from '../axiosAPIs';
|
||||||
import { fetchAuthorizerConfig } from '../axiosAPIs/miscAPI';
|
import { fetchAuthorizerConfig } from '../axiosAPIs/miscAPI';
|
||||||
import {
|
import {
|
||||||
getLoggedInUser,
|
getLoggedInUser,
|
||||||
@ -38,7 +39,9 @@ import {
|
|||||||
getUsers,
|
getUsers,
|
||||||
} from '../axiosAPIs/userAPI';
|
} from '../axiosAPIs/userAPI';
|
||||||
import { oidcTokenKey, ROUTES, TIMEOUT } from '../constants/constants';
|
import { oidcTokenKey, ROUTES, TIMEOUT } from '../constants/constants';
|
||||||
|
import { ClientErrors } from '../enums/axios.enum';
|
||||||
import { useAuth } from '../hooks/authHooks';
|
import { useAuth } from '../hooks/authHooks';
|
||||||
|
import useToastContext from '../hooks/useToastContext';
|
||||||
import SigninPage from '../pages/login';
|
import SigninPage from '../pages/login';
|
||||||
import PageNotFound from '../pages/page-not-found';
|
import PageNotFound from '../pages/page-not-found';
|
||||||
import {
|
import {
|
||||||
@ -65,6 +68,7 @@ const AuthProvider: FunctionComponent<AuthProviderProps> = ({
|
|||||||
children,
|
children,
|
||||||
}: AuthProviderProps) => {
|
}: AuthProviderProps) => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const showToast = useToastContext();
|
||||||
const { isSignedIn, isSigningIn, isSignedOut } = useAuth();
|
const { isSignedIn, isSigningIn, isSignedOut } = useAuth();
|
||||||
|
|
||||||
const oidcUserToken = cookieStorage.getItem(oidcTokenKey);
|
const oidcUserToken = cookieStorage.getItem(oidcTokenKey);
|
||||||
@ -190,6 +194,24 @@ const AuthProvider: FunctionComponent<AuthProviderProps> = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchAuthConfig();
|
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(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@ -18,10 +18,10 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { CookieStorage } from 'cookie-storage';
|
import { CookieStorage } from 'cookie-storage';
|
||||||
import { oidcTokenKey } from '../constants/constants';
|
import { oidcTokenKey } from '../constants/constants';
|
||||||
|
import { ClientErrors } from '../enums/axios.enum';
|
||||||
import { userSignOut } from '../utils/AuthUtils';
|
import { userSignOut } from '../utils/AuthUtils';
|
||||||
|
|
||||||
const cookieStorage = new CookieStorage();
|
const cookieStorage = new CookieStorage();
|
||||||
const UNAUTHORIZED = 401;
|
|
||||||
|
|
||||||
const axiosClient = axios.create({
|
const axiosClient = axios.create({
|
||||||
baseURL: '/api/v1',
|
baseURL: '/api/v1',
|
||||||
@ -41,7 +41,7 @@ axiosClient.interceptors.response.use(
|
|||||||
(error) => {
|
(error) => {
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
const { status } = error.response;
|
const { status } = error.response;
|
||||||
if (status === UNAUTHORIZED) {
|
if (status === ClientErrors.UNAUTHORIZED) {
|
||||||
userSignOut();
|
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