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 BACK = 'BACK';
export const LOGINPROGRESS = 'LOGINPROGRESS';
export const LOGINSUCCESS = 'LOGINSUCCESS';
export const LOGINFAILURE = 'LOGINFAILURE';
import * as types from './actionTypes';
export function loginold(username, password) {
export function loginSuccess(username) {
return {
type: types.LOGIN,
success: password === '42',
type: types.LOGINSUCCESS,
};
}
export function login(username, password) {
return (dispatch) => {
dispatch(loginProgress());
return fetch('https://thalia.nu/api/login', {
method: 'POST',
})
......@@ -17,8 +17,29 @@ export function login(username, password) {
.then(
(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