Start implementing backends and authentication
This commit is contained in:
38
src/actions/auth.js
Normal file
38
src/actions/auth.js
Normal file
@ -0,0 +1,38 @@
|
||||
import { currentBackend } from '../backends/backend';
|
||||
|
||||
export const AUTH_REQUEST = 'AUTH_REQUEST';
|
||||
export const AUTH_SUCCESS = 'AUTH_SUCCESS';
|
||||
export const AUTH_FAILURE = 'AUTH_FAILURE';
|
||||
|
||||
export function authenticating() {
|
||||
return {
|
||||
type: AUTH_REQUEST
|
||||
};
|
||||
}
|
||||
|
||||
export function authenticate(userData) {
|
||||
return {
|
||||
type: AUTH_SUCCESS,
|
||||
payload: userData
|
||||
};
|
||||
}
|
||||
|
||||
export function authError(error) {
|
||||
return {
|
||||
type: AUTH_FAILURE,
|
||||
error: 'Failed to authenticate',
|
||||
payload: error,
|
||||
};
|
||||
}
|
||||
|
||||
export function loginUser(credentials) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = currentBackend(state.config);
|
||||
|
||||
dispatch(authenticating());
|
||||
backend.authenticate(credentials)
|
||||
.then((user) => dispatch(authenticate(user)))
|
||||
.catch((err) => dispatch(authError(err)));
|
||||
};
|
||||
}
|
@ -1,27 +1,25 @@
|
||||
import yaml from 'js-yaml';
|
||||
|
||||
export const CONFIG = {
|
||||
REQUEST: 'REQUEST',
|
||||
SUCCESS: 'SUCCESS',
|
||||
FAILURE: 'FAILURE'
|
||||
};
|
||||
export const CONFIG_REQUEST = 'CONFIG_REQUEST';
|
||||
export const CONFIG_SUCCESS = 'CONFIG_SUCCESS';
|
||||
export const CONFIG_FAILURE = 'CONFIG_FAILURE';
|
||||
|
||||
export function configLoaded(config) {
|
||||
return {
|
||||
type: CONFIG.SUCCESS,
|
||||
type: CONFIG_SUCCESS,
|
||||
payload: config
|
||||
};
|
||||
}
|
||||
|
||||
export function configLoading() {
|
||||
return {
|
||||
type: CONFIG.REQUEST
|
||||
type: CONFIG_REQUEST
|
||||
};
|
||||
}
|
||||
|
||||
export function configFailed(err) {
|
||||
return {
|
||||
type: CONFIG.FAILURE,
|
||||
type: CONFIG_FAILURE,
|
||||
error: 'Error loading config',
|
||||
payload: err
|
||||
};
|
||||
|
Reference in New Issue
Block a user