2022-07-11 12:30:37 +00:00
|
|
|
import ReducerRegistry from '../base/redux/ReducerRegistry';
|
2022-07-01 09:32:39 +00:00
|
|
|
import { assign } from '../base/redux/functions';
|
2017-09-08 13:36:42 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
CANCEL_LOGIN,
|
|
|
|
STOP_WAIT_FOR_OWNER,
|
2017-09-18 07:09:43 +00:00
|
|
|
UPGRADE_ROLE_FINISHED,
|
|
|
|
UPGRADE_ROLE_STARTED,
|
2017-09-08 13:36:42 +00:00
|
|
|
WAIT_FOR_OWNER
|
|
|
|
} from './actionTypes';
|
|
|
|
|
2022-07-01 09:32:39 +00:00
|
|
|
export interface IAuthenticationState {
|
2022-09-08 09:52:36 +00:00
|
|
|
error?: Object | undefined;
|
|
|
|
progress?: number | undefined;
|
2022-11-10 08:45:56 +00:00
|
|
|
thenableWithCancel?: {
|
|
|
|
cancel: Function;
|
|
|
|
};
|
2022-07-01 09:32:39 +00:00
|
|
|
waitForOwnerTimeoutID?: number;
|
|
|
|
}
|
|
|
|
|
2021-03-24 14:09:40 +00:00
|
|
|
/**
|
|
|
|
* Listens for actions which change the state of the authentication feature.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of the authentication feature.
|
|
|
|
* @param {Object} action - Action object.
|
|
|
|
* @param {string} action.type - Type of action.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<IAuthenticationState>('features/authentication',
|
|
|
|
(state = {}, action): IAuthenticationState => {
|
2017-09-08 13:36:42 +00:00
|
|
|
switch (action.type) {
|
2017-09-18 07:09:43 +00:00
|
|
|
case CANCEL_LOGIN:
|
2017-09-08 13:36:42 +00:00
|
|
|
return assign(state, {
|
2017-09-24 23:41:20 +00:00
|
|
|
error: undefined,
|
|
|
|
progress: undefined,
|
|
|
|
thenableWithCancel: undefined
|
2017-09-08 13:36:42 +00:00
|
|
|
});
|
2017-09-18 07:09:43 +00:00
|
|
|
|
|
|
|
case STOP_WAIT_FOR_OWNER:
|
2017-09-08 13:36:42 +00:00
|
|
|
return assign(state, {
|
2017-09-24 23:41:20 +00:00
|
|
|
error: undefined,
|
2017-09-18 07:09:43 +00:00
|
|
|
waitForOwnerTimeoutID: undefined
|
2017-09-08 13:36:42 +00:00
|
|
|
});
|
2017-09-18 07:09:43 +00:00
|
|
|
|
2017-09-24 23:41:20 +00:00
|
|
|
case UPGRADE_ROLE_FINISHED: {
|
|
|
|
let { thenableWithCancel } = action;
|
|
|
|
|
|
|
|
if (state.thenableWithCancel === thenableWithCancel) {
|
|
|
|
const { error, progress } = action;
|
2017-09-22 19:06:16 +00:00
|
|
|
|
2017-09-24 23:41:20 +00:00
|
|
|
// An error interrupts the process of authenticating and upgrading
|
|
|
|
// the role of the local participant/user i.e. the process is no
|
|
|
|
// more. Obviously, the process seizes to exist also when it does
|
|
|
|
// its whole job.
|
|
|
|
if (error || progress === 1) {
|
|
|
|
thenableWithCancel = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return assign(state, {
|
|
|
|
error,
|
|
|
|
progress: progress || undefined,
|
|
|
|
thenableWithCancel
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case UPGRADE_ROLE_STARTED:
|
2017-09-22 19:06:16 +00:00
|
|
|
return assign(state, {
|
2017-09-24 23:41:20 +00:00
|
|
|
error: undefined,
|
|
|
|
progress: undefined,
|
|
|
|
thenableWithCancel: action.thenableWithCancel
|
2017-09-08 13:36:42 +00:00
|
|
|
});
|
2017-09-18 07:09:43 +00:00
|
|
|
|
|
|
|
case WAIT_FOR_OWNER:
|
2017-09-08 13:36:42 +00:00
|
|
|
return assign(state, {
|
2017-09-18 07:09:43 +00:00
|
|
|
waitForOwnerTimeoutID: action.waitForOwnerTimeoutID
|
2017-09-08 13:36:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|