2022-07-19 07:58:56 +00:00
|
|
|
import ReducerRegistry from '../redux/ReducerRegistry';
|
|
|
|
import { equals } from '../redux/functions';
|
2017-04-21 10:00:50 +00:00
|
|
|
|
2018-06-26 22:56:22 +00:00
|
|
|
import { SET_JWT } from './actionTypes';
|
2017-04-21 10:00:50 +00:00
|
|
|
|
2022-07-19 07:58:56 +00:00
|
|
|
export interface IJwtState {
|
2022-09-19 07:40:03 +00:00
|
|
|
callee?: {
|
|
|
|
name: string;
|
|
|
|
};
|
2022-09-06 12:51:50 +00:00
|
|
|
group?: string;
|
2022-07-19 07:58:56 +00:00
|
|
|
jwt?: string;
|
2022-09-06 12:51:50 +00:00
|
|
|
server?: string;
|
2022-09-19 07:40:03 +00:00
|
|
|
tenant?: string;
|
2022-09-23 09:03:25 +00:00
|
|
|
user?: {
|
2022-10-07 08:39:18 +00:00
|
|
|
id: string;
|
2022-09-23 09:03:25 +00:00
|
|
|
name: string;
|
|
|
|
};
|
2022-07-19 07:58:56 +00:00
|
|
|
}
|
|
|
|
|
2017-04-21 10:00:50 +00:00
|
|
|
/**
|
|
|
|
* Reduces redux actions which affect the JSON Web Token (JWT) stored in the
|
|
|
|
* redux store.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The current redux state.
|
|
|
|
* @param {Object} action - The redux action to reduce.
|
|
|
|
* @returns {Object} The next redux state which is the result of reducing the
|
|
|
|
* specified {@code action}.
|
|
|
|
*/
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<IJwtState>(
|
2017-10-12 19:59:11 +00:00
|
|
|
'features/base/jwt',
|
2022-09-05 09:05:07 +00:00
|
|
|
(state = {}, action): IJwtState => {
|
2017-10-12 19:59:11 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case SET_JWT: {
|
2022-07-19 07:58:56 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2017-10-12 19:59:11 +00:00
|
|
|
const { type, ...payload } = action;
|
|
|
|
const nextState = {
|
|
|
|
...payload
|
|
|
|
};
|
|
|
|
|
|
|
|
return equals(state, nextState) ? state : nextState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|