UNPKG

stitch-ui

Version:

34 lines (27 loc) 1.03 kB
import { createAction } from "redux-act"; import { makeAsyncActions, asyncActionExecutor } from "../util"; const NAME = "session/"; export const loadRootAuthProvidersActions = makeAsyncActions( `${NAME}load root auth providers` ); export const loginActions = makeAsyncActions(`${NAME}login`); export const setLoginErrorAction = createAction(`${NAME}set login error`); export const setLoginError = error => setLoginErrorAction({ error }); export const loadRootAuthProviders = asyncActionExecutor( loadRootAuthProvidersActions, client => () => client.client // eslint-disable-line no-underscore-dangle ._do("/login", "GET", { noAuth: true }) .then(response => response.json()) ); export const login = asyncActionExecutor( loginActions, (client, username, password) => () => client.client.login(username, password), true ); export const loginCloud = asyncActionExecutor( loginActions, (client, username, apiKey) => () => client.client.authManager.mongodbCloudAuth(username, apiKey), true );