const AUTH_REQUIRED = 'auth/REQUIRED';
const LOGOUT = 'auth/LOGOUT';
const SET_LOGGED_IN_USER = 'auth/SET_LOGGED_IN_USER';
const SUBMIT_CREDENTIALS = 'auth/SUBMIT_CREDENTIALS';
const SET_RE_AUTHENTICATION = 'auth/SET_RE_AUTHENTICATION';
const SET_IMAGE_DATA_URL = 'auth/SET_IMAGE_DATA_URL';
/**
* Provides a possibility to work with user authentication and login screen.
*
* @module auth
*/
export default {
AUTH_REQUIRED,
/**
* Authenticates the user based on the saved data in the system.
*
* Therefore before calling this action, you need to save information about the current user with help of
* {setLoggedInUser} action.
*
* @property {string} type - AUTH_REQUIRED
*/
authRequired: () => ({type: AUTH_REQUIRED}),
LOGOUT,
/**
* Calls API to logout the current user and wipes all information about logged in user from Redux store.
*
* @property {string} type - LOGOUT
*/
logout: () => ({type: LOGOUT}),
SET_IMAGE_DATA_URL,
SET_LOGGED_IN_USER,
SET_RE_AUTHENTICATION,
/**
* When user loses the session we make the page not accessible and display the modal window to re-authenticate.
* On top of that we also make the page blurred with help of the image.
* This action specifically dedicated to define that image.
*
* @param imageDataUrl {string} - The URL to an image which will be layered on top of the whole page
* @property {string} type - SET_IMAGE_DATA_URL
*/
setImageDataUrl: (imageDataUrl) => ({
imageDataUrl,
type: SET_IMAGE_DATA_URL
}),
/**
* Saves the information about logged in user.
*
* @param username {string} - the name of currently logged in user.
* @param viewAs {object} - Represented as {user, roles}, where user is string and roles - array of strings.
* @param loginProviders {object} - Structure of the object is {isLocalUrl, loginUrl, logoutUrl}.
* loginUrl - is the link which will be called when user sign in.
* logoutUrl - is the link which will be called when user sign out.
* isLocalUrl - specifies if XLD has enabled or disabled SSO.
*
* @property {string} type - SET_LOGGED_IN_USER
*/
setLoggedInUser: (
{username, viewAs, loginProviders}) => (
{
loginProviders,
type: SET_LOGGED_IN_USER,
username,
viewAs
}),
/**
* Notifies the user that the session is lost and requires to reauthenticate.
* At this case the appropriate modal window is displayed and the main page is blurred, so no actions are allowed
* and nothing is visible.
*
* @param reAuthentication {boolean} - if true, displays re-authentication modal window
* @param reAuthenticationMessage {string} - a title of the modal window
* @param reAuthenticationDescription {string} - a description in the modal window explaining to the
* user what is happening now.
*
* @property {string} type - SET_RE_AUTHENTICATION
*/
setReAuthentication: (reAuthentication, reAuthenticationMessage, reAuthenticationDescription) =>
({
reAuthentication,
reAuthenticationDescription,
reAuthenticationMessage,
type: SET_RE_AUTHENTICATION
}),
SUBMIT_CREDENTIALS,
/**
* Submits provided credentials of the user for singing in to the system.
*
* @param password {string} - password credential of the user
* @param rememberMe {boolean} - should the session be saved in rememberMe cookie
* @param username {string} - login credential of the user
*
* @property {string} type - SUBMIT_CREDENTIALS
*/
submitCredentials: ({password, rememberMe = false, username}) => ({
password,
rememberMe,
type: SUBMIT_CREDENTIALS,
username
})
};
Source