Commit 790a6cf0 authored by AuckeBos's avatar AuckeBos
Browse files

Async connection with response working

parent 1ae6260c
export const LOGIN = 'LOGIN';
export const NAVIGATE = 'NAVIGATE'; export const NAVIGATE = 'NAVIGATE';
export const BACK = 'BACK'; export const BACK = 'BACK';
export const LOGINPROGRESS = 'LOGINPROGRESS';
export const LOGINSUCCESS = 'LOGINSUCCESS';
export const LOGINFAILURE = 'LOGINFAILURE';
import * as types from './actionTypes'; import * as types from './actionTypes';
export function loginold(username, password) { export function loginSuccess(username) {
return { return {
type: types.LOGIN, type: types.LOGINSUCCESS,
success: password === '42',
}; };
} }
export function login(username, password) { export function login(username, password) {
return (dispatch) => { return (dispatch) => {
dispatch(loginProgress());
return fetch('https://thalia.nu/api/login', { return fetch('https://thalia.nu/api/login', {
method: 'POST', method: 'POST',
}) })
...@@ -17,8 +17,29 @@ export function login(username, password) { ...@@ -17,8 +17,29 @@ export function login(username, password) {
.then( .then(
(responseJson) => { (responseJson) => {
console.log(responseJson); console.log(responseJson);
return dispatch(loginold(username, password)); if(password === '42'){
console.log(responseJson);
return dispatch(loginSuccess(username))
}
else{
return dispatch(loginFailure());
}
}) })
.catch(error => console.error(error)); .catch(error => {
console.error(error);
return dispatch(loginFailure());
});
};
}
export function loginProgress() {
return {
type: types.LOGINPROGRESS,
};
}
export function loginFailure(){
return{
type: types.LOGINFAILURE,
}; };
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment