From b26486a72a29b160399fc68eee33999cd035b168 Mon Sep 17 00:00:00 2001 From: Pierce Trey Date: Wed, 5 May 2021 15:38:42 -0600 Subject: [PATCH] remove auth flow - ui will be for external users or behind internal google oauth --- src/App.js | 26 ++-------------- src/AppContainer.tsx | 6 +--- src/interceptors/401-interceptor.ts | 22 -------------- src/interceptors/index.ts | 2 -- src/interceptors/jwt-interceptor.ts | 47 ----------------------------- src/reducers/identity-reducer.ts | 37 ----------------------- src/reducers/index.ts | 2 -- src/store/index.js | 3 -- 8 files changed, 3 insertions(+), 142 deletions(-) delete mode 100644 src/interceptors/401-interceptor.ts delete mode 100644 src/interceptors/index.ts delete mode 100644 src/interceptors/jwt-interceptor.ts delete mode 100644 src/reducers/identity-reducer.ts diff --git a/src/App.js b/src/App.js index 6f29b53..ad9b7a9 100644 --- a/src/App.js +++ b/src/App.js @@ -1,35 +1,13 @@ -import React, { useEffect } from 'react'; +import React from 'react'; import { Switch, Route, Redirect } from 'react-router-dom'; import DashboardContainer from 'components/Dashboard/DashboardContainer'; import { ContractContainer, ContractListContainer } from 'components/Contract'; -import { LoginContainer } from 'components/Login'; import { KeyManagerContainer, AddServiceKeyModal } from 'components/KeyManagement'; -import { OAuthCallback } from 'components/OAuth'; import KeyDetailsContainer from 'components/KeyManagement/KeyDetailsContainer'; import { ScopeContainer, ScopeHistoryContainer, ScopeListContainer } from 'components/Scopes'; import { Settings } from 'Constant'; -import { useDeepLink } from 'hooks'; - -const App = ({ isAuthenticated }) => { - const { performDeepLink } = useDeepLink(); - - useEffect(() => { - if (isAuthenticated) { - performDeepLink(); - } - }, [isAuthenticated, performDeepLink]); - - if (!isAuthenticated) { - return ( - <> - - - - - - ); - } +const App = () => { return ( <> diff --git a/src/AppContainer.tsx b/src/AppContainer.tsx index 7c72b66..790d164 100644 --- a/src/AppContainer.tsx +++ b/src/AppContainer.tsx @@ -1,14 +1,10 @@ import React from 'react'; -import { useSelector } from 'react-redux'; import App from 'App'; import { ErrorCardContainer } from 'components/ErrorCards'; export const AppContainer = () => { - const { jwt } = useSelector(({ identityReducer }) => identityReducer); - const isAuthenticated = typeof jwt === 'string' && jwt.length > 0; - return (<> - + ); } \ No newline at end of file diff --git a/src/interceptors/401-interceptor.ts b/src/interceptors/401-interceptor.ts deleted file mode 100644 index 60728fc..0000000 --- a/src/interceptors/401-interceptor.ts +++ /dev/null @@ -1,22 +0,0 @@ -import store from 'store'; -import { logout } from 'actions/identity-actions'; -import { addError, ErrorLevels } from 'actions/error-actions'; -import debounce from 'lodash.debounce'; -import { axios } from 'actions'; - -const handle401 = debounce(() => { - store.dispatch(addError('Unauthenticated, please log in again', ErrorLevels.WARNING)); - store.dispatch(logout()); -}, 1000) - -export const setup401Interceptor = () => { - axios.interceptors.response.use(response => response, - error => { - const response = error.response; - if (response?.status === 401) { - handle401(); - } - - throw error; - }) -} \ No newline at end of file diff --git a/src/interceptors/index.ts b/src/interceptors/index.ts deleted file mode 100644 index 7aecccc..0000000 --- a/src/interceptors/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { setupJwtInterceptor } from './jwt-interceptor'; -export { setup401Interceptor } from './401-interceptor'; \ No newline at end of file diff --git a/src/interceptors/jwt-interceptor.ts b/src/interceptors/jwt-interceptor.ts deleted file mode 100644 index e475fea..0000000 --- a/src/interceptors/jwt-interceptor.ts +++ /dev/null @@ -1,47 +0,0 @@ -import store from 'store'; -import { jwtStorageKey } from 'reducers/identity-reducer'; -import { logout, login } from 'actions/identity-actions'; -import { axios } from 'actions'; - -const storeJwt = (): string | null => store.getState()?.identityReducer?.jwt; - -const getInterceptor = (jwt?: string) => config => { - config = { - ...config, - headers: { - ...config.headers, - Authorization: `Bearer ${jwt}` - } - } - - return config; -}; - -let interceptor; -export const setupJwtInterceptor = (jwt: string = '') => { - if (interceptor !== undefined) { - axios.interceptors.request.eject(interceptor); - } - - interceptor = axios.interceptors.request.use(getInterceptor(jwt)); -} - -axios.interceptors.response.use(response => { - if (response?.headers?.authorization) { - store.dispatch(login(response.headers.authorization)) - } - return response; -}) - -window.addEventListener('storage', (e) => { - if (!e.key || e.key === jwtStorageKey) { - const exitingJwt = storeJwt(); - const newJwt = window.localStorage.getItem(jwtStorageKey); - - if (exitingJwt && !newJwt) { - store.dispatch(logout()); - } else if (newJwt && exitingJwt !== newJwt) { - store.dispatch(login(newJwt)); - } - } -}) \ No newline at end of file diff --git a/src/reducers/identity-reducer.ts b/src/reducers/identity-reducer.ts deleted file mode 100644 index bcff56b..0000000 --- a/src/reducers/identity-reducer.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { handleActions } from "redux-actions" -import { LOGOUT, LOGIN } from "actions/identity-actions"; -import { setupJwtInterceptor } from "interceptors"; - -export const jwtStorageKey = 'jwt'; - -const initialState = (() => { - const storedJwt = window.localStorage.getItem(jwtStorageKey); - setupJwtInterceptor(storedJwt || ''); - - return { - jwt: storedJwt || '', - }; -})(); - -const identityReducer = handleActions({ - [LOGOUT]: (state, action) => { - window.localStorage.setItem(jwtStorageKey, ''); - setupJwtInterceptor(); - - return { - ...state, - jwt: '' - } - }, - [LOGIN]: (state, { payload: jwt }) => { - window.localStorage.setItem(jwtStorageKey, jwt); - setupJwtInterceptor(jwt); - - return { - ...state, - jwt - } - } -}, initialState); - -export default identityReducer; \ No newline at end of file diff --git a/src/reducers/index.ts b/src/reducers/index.ts index 69d3b9b..198d08f 100644 --- a/src/reducers/index.ts +++ b/src/reducers/index.ts @@ -2,7 +2,6 @@ import { default as contractReducer } from './contract-reducer'; import { default as scopeReducer } from './scope-reducer'; import { default as objectReducer } from './object-reducer'; import { default as keyReducer } from './key-reducer'; -import { default as identityReducer } from './identity-reducer'; import { default as errorReducer } from './error-reducer'; export default { @@ -10,6 +9,5 @@ export default { scopeReducer, objectReducer, keyReducer, - identityReducer, errorReducer, }; diff --git a/src/store/index.js b/src/store/index.js index 71bbc69..c9660c1 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,7 +1,6 @@ import { applyMiddleware, createStore, combineReducers, compose } from 'redux'; import thunk from 'redux-thunk'; import rootReducer from 'reducers'; -import { setup401Interceptor } from 'interceptors'; const middleware = [ thunk, // thunk middleware allows us to return promises from and receive dispatch reference in redux action creators. @@ -23,6 +22,4 @@ const composedEnhancers = compose(applyMiddleware(...middleware), ...enhancers); const store = createStore(combineReducers({ ...rootReducer }), preloadedState, composedEnhancers); -setup401Interceptor(); - export default store;