mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-18 01:18:23 +02:00
* fix: strategy dialogue * fix: fontweight dropdown * fix: eventlog padding * refactor: history * refactor: use material ui styling conventions for history * refactor: add empty state for features * refactor: variant dialog * refactor: delete unused variant config * fix: variant typography * fix: remove unused styles file * fix: footer * feat: protected routes * fix: rename app * fix: remove console log * fix: convert app to typescript * fix: add standalone login screen * fix: cleanup * fix: add theme colors for login * fix: update tests * fix: swap route with ProtectedRoute * fix: remove unused redirect * fix: use redirect to correctly setup breadcrumbs * refactor: isUnauthorized * fix: reset loading count on logout * fix: create a more comprehensive auth check * feat: add unleash logo
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
import api from './api';
|
|
import { dispatchError } from '../util';
|
|
import { RESET_LOADING } from '../feature-toggle/actions';
|
|
export const USER_CHANGE_CURRENT = 'USER_CHANGE_CURRENT';
|
|
export const USER_LOGOUT = 'USER_LOGOUT';
|
|
export const USER_LOGIN = 'USER_LOGIN';
|
|
export const START_FETCH_USER = 'START_FETCH_USER';
|
|
export const ERROR_FETCH_USER = 'ERROR_FETCH_USER';
|
|
const debug = require('debug')('unleash:user-actions');
|
|
|
|
const updateUser = value => ({
|
|
type: USER_CHANGE_CURRENT,
|
|
value,
|
|
});
|
|
|
|
function handleError(error) {
|
|
debug(error);
|
|
}
|
|
|
|
export function fetchUser() {
|
|
debug('Start fetching user');
|
|
return dispatch => {
|
|
dispatch({ type: START_FETCH_USER });
|
|
|
|
return api
|
|
.fetchUser()
|
|
.then(json => dispatch(updateUser(json)))
|
|
.catch(dispatchError(dispatch, ERROR_FETCH_USER));
|
|
};
|
|
}
|
|
|
|
export function insecureLogin(path, user) {
|
|
return dispatch => {
|
|
dispatch({ type: START_FETCH_USER });
|
|
|
|
return api
|
|
.insecureLogin(path, user)
|
|
.then(json => dispatch(updateUser(json)))
|
|
.catch(handleError);
|
|
};
|
|
}
|
|
|
|
export function passwordLogin(path, user) {
|
|
return dispatch => {
|
|
dispatch({ type: START_FETCH_USER });
|
|
|
|
return api
|
|
.passwordLogin(path, user)
|
|
.then(json => dispatch(updateUser(json)))
|
|
.then(() => dispatch({ type: USER_LOGIN }));
|
|
};
|
|
}
|
|
|
|
export function logoutUser() {
|
|
return dispatch => {
|
|
return api
|
|
.logoutUser()
|
|
.then(() => dispatch({ type: USER_LOGOUT }))
|
|
.then(() => dispatch({ type: RESET_LOADING }))
|
|
.catch(handleError);
|
|
};
|
|
}
|