client/src/selectors/authSelectors.js
author ymh <ymh.work@gmail.com>
Fri, 30 Nov 2018 10:53:15 +0100
changeset 183 f8f3af9e5c83
parent 170 7da1d5137b0b
permissions -rw-r--r--
Change the settings to avoid using Session authentication for rest framework as it raise exceptions in case client and backend are on the same domain On the filter, adapt to take into account new version of django_filters

// Selectors linked to the authentication status
import * as R from 'ramda';

export const getOnline = R.path(["status", 'online'])

export const getToken = R.path(['authStatus','token'])

export const isAuthenticated = R.path(['authStatus', 'isAuthenticated'])

export const getCurrentUser = R.path(['authStatus', 'currentUser'])

export const getClientId = R.path(['authStatus', 'clientId'])

export const getCurrentGroupName = R.path(['authStatus', 'currentGroup'])

export const getGroups = R.prop('groups')

const findByName = R.compose(R.find, R.propEq('name'));
const findByGroupName = R.compose(findByName, getCurrentGroupName);

// export const getCurrentGroup = state => {
//   const groupName = getCurrentGroupName(state);
//   const groups = getGroups(state);
//   if(groups) {
//     return groups.find( g => g['name'] === groupName );
//   } else {
//     return null;
//   }
// }
// https://stackoverflow.com/a/48924396

export const getCurrentGroup = R.unnest(R.converge(R.compose, [findByGroupName, R.always(getGroups)]))

export const getCreateGroup = R.prop('createGroup')

export const getAutoSubmit = R.prop('autoSubmit')

export const getLoginErrorMessages = R.path(['login', 'errorMessages'])