Start implementing backends and authentication

This commit is contained in:
Mathias Biilmann Christensen
2016-02-25 12:31:21 -08:00
parent c60d8ba706
commit 67cdd92bfb
13 changed files with 247 additions and 15 deletions

38
src/actions/auth.js Normal file
View 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)));
};
}

View File

@ -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
};