Files
planka/client/src/sagas/login/services/router.js

68 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-10-17 19:18:19 +02:00
import { call, put, select, take } from 'redux-saga/effects';
import { push } from '../../../lib/redux-router';
2019-08-31 04:07:25 +05:00
import { authenticateUsingOidc, authenticateUsingOidcCallback } from './login';
2022-08-04 13:31:14 +02:00
import selectors from '../../../selectors';
2023-10-17 19:18:19 +02:00
import ActionTypes from '../../../constants/ActionTypes';
2019-08-31 04:07:25 +05:00
import Paths from '../../../constants/Paths';
2022-08-04 13:31:14 +02:00
export function* goToLogin() {
2019-08-31 04:07:25 +05:00
yield put(push(Paths.LOGIN));
}
2022-08-04 13:31:14 +02:00
export function* goToRoot() {
2019-08-31 04:07:25 +05:00
yield put(push(Paths.ROOT));
}
2022-08-04 13:31:14 +02:00
export function* handleLocationChange() {
const pathsMatch = yield select(selectors.selectPathsMatch);
2019-08-31 04:07:25 +05:00
if (!pathsMatch) {
return;
}
2022-11-21 00:54:05 +01:00
switch (pathsMatch.pattern.path) {
2019-08-31 04:07:25 +05:00
case Paths.ROOT:
case Paths.PROJECTS:
case Paths.BOARDS:
case Paths.CARDS:
2022-08-04 13:31:14 +02:00
yield call(goToLogin);
2019-08-31 04:07:25 +05:00
break;
default:
}
const isInitializing = yield select(selectors.selectIsInitializing);
2023-10-17 19:18:19 +02:00
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);
}
2023-10-17 19:18:19 +02:00
}
break;
}
case Paths.OIDC_CALLBACK:
2023-10-19 16:05:34 +02:00
yield call(authenticateUsingOidcCallback);
2023-10-17 19:18:19 +02:00
break;
2019-08-31 04:07:25 +05:00
default:
}
}
2022-08-04 13:31:14 +02:00
export default {
goToLogin,
goToRoot,
handleLocationChange,
};