diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-05-16 23:18:02 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-05-18 15:46:42 +0200 |
| commit | a6865b86cc8d710374fc0b6cfcbd2b863f1942a9 (patch) | |
| tree | 121fdb26827c5509a12a4427e8f9d881dbdefe82 /opendc-web/opendc-web-ui/src/redux/index.js | |
| parent | 6412610f38117e1ea0635a56fa023183723fa67a (diff) | |
ui: Migrate to Auth0 as Identity Provider
This change updates the frontend codebase to move away from the Google
login and instead use Auth0 as generic Identity Provider. This allows
users to login with other accounts as well.
Since Auth0 has a free tier, users can experiment themselves with OpenDC
locally without having to pay for the login functionality. The code has
been written so that we should be able to migrate away from Auth0 once
it is not a suitable Identity Provider for OpenDC anymore.
Diffstat (limited to 'opendc-web/opendc-web-ui/src/redux/index.js')
| -rw-r--r-- | opendc-web/opendc-web-ui/src/redux/index.js | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/opendc-web/opendc-web-ui/src/redux/index.js b/opendc-web/opendc-web-ui/src/redux/index.js index c706752b..ee6ca3f5 100644 --- a/opendc-web/opendc-web-ui/src/redux/index.js +++ b/opendc-web/opendc-web-ui/src/redux/index.js @@ -1,40 +1,32 @@ import { useMemo } from 'react' -import { applyMiddleware, compose, createStore } from 'redux' +import { applyMiddleware, createStore } from 'redux' import { createLogger } from 'redux-logger' -import persistState from 'redux-localstorage' import createSagaMiddleware from 'redux-saga' import thunk from 'redux-thunk' -import { authRedirectMiddleware } from '../auth' import rootReducer from './reducers' import rootSaga from './sagas' import { viewportAdjustmentMiddleware } from './middleware/viewport-adjustment' let store -function initStore(initialState) { - const sagaMiddleware = createSagaMiddleware() +function initStore(initialState, ctx) { + const sagaMiddleware = createSagaMiddleware({ context: ctx }) - const middlewares = [thunk, sagaMiddleware, authRedirectMiddleware, viewportAdjustmentMiddleware] + const middlewares = [thunk, sagaMiddleware, viewportAdjustmentMiddleware] if (process.env.NODE_ENV !== 'production') { middlewares.push(createLogger()) } - let enhancer = applyMiddleware(...middlewares) - - if (global.localStorage) { - enhancer = compose(persistState('auth'), enhancer) - } - - const configuredStore = createStore(rootReducer, enhancer) + const configuredStore = createStore(rootReducer, initialState, applyMiddleware(...middlewares)) sagaMiddleware.run(rootSaga) store = configuredStore return configuredStore } -export const initializeStore = (preloadedState) => { - let _store = store ?? initStore(preloadedState) +export const initializeStore = (preloadedState, ctx) => { + let _store = store ?? initStore(preloadedState, ctx) // After navigating to a page with an initial Redux state, merge that state // with the current state in the store, and create a new store @@ -55,6 +47,6 @@ export const initializeStore = (preloadedState) => { return _store } -export function useStore(initialState) { - return useMemo(() => initializeStore(initialState), [initialState]) +export function useStore(initialState, ctx) { + return useMemo(() => initializeStore(initialState, ctx), [initialState, ctx]) } |
