import { call, put, select, take } from 'redux-saga/effects'; import { push } from '../../../lib/redux-router'; import { authenticateUsingOidc, authenticateUsingOidcCallback } from './login'; import selectors from '../../../selectors'; import ActionTypes from '../../../constants/ActionTypes'; import Paths from '../../../constants/Paths'; export function* goToLogin() { yield put(push(Paths.LOGIN)); } export function* goToRoot() { yield put(push(Paths.ROOT)); } export function* handleLocationChange() { const pathsMatch = yield select(selectors.selectPathsMatch); if (!pathsMatch) { return; } switch (pathsMatch.pattern.path) { case Paths.ROOT: case Paths.PROJECTS: case Paths.BOARDS: case Paths.CARDS: yield call(goToLogin); break; default: } const isInitializing = yield select(selectors.selectIsInitializing); if (isInitializing) { yield take(ActionTypes.LOGIN_INITIALIZE); } switch (pathsMatch.pattern.path) { case Paths.LOGIN: { const oidcConfig = yield select(selectors.selectOidcConfig); if (oidcConfig) { const params = new URLSearchParams(window.location.search); if (params.has('authenticateWithOidc')) { yield call(authenticateUsingOidc); } } break; } case Paths.OIDC_CALLBACK: yield call(authenticateUsingOidcCallback); break; default: } } export default { goToLogin, goToRoot, handleLocationChange, };