Commit 00544c2f authored by Sonja Happ's avatar Sonja Happ
Browse files

save user information from login response of backend, omit users/me endpoint

parent f72d7b89
......@@ -32,7 +32,8 @@ class UsersDataManager extends RestDataManager {
RestAPI.post(this.makeURL('/authenticate'), { username: username, password: password }).then(response => {
AppDispatcher.dispatch({
type: 'users/logged-in',
token: response.token
token: response.token,
user: response.user
});
}).catch(error => {
AppDispatcher.dispatch({
......@@ -42,19 +43,19 @@ class UsersDataManager extends RestDataManager {
});
}
getCurrentUser(token) {
RestAPI.get(this.makeURL('/users/me'), token).then(response => {
AppDispatcher.dispatch({
type: 'users/current-user',
user: response.user
});
}).catch(error => {
AppDispatcher.dispatch({
type: 'users/current-user-error',
error: error
});
});
}
//getCurrentUser(token) {
// RestAPI.get(this.makeURL('/users/me'), token).then(response => {
// AppDispatcher.dispatch({
// type: 'users/current-user',
// user: response.user
// });
// }).catch(error => {
// AppDispatcher.dispatch({
// type: 'users/current-user-error',
// error: error
// });
// });
//}
}
......
......@@ -53,14 +53,15 @@ class UserStore extends ReduceStore {
return Object.assign({}, state, { token: null, currentUser: null });
case 'users/logged-in':
// request logged-in user data
UsersDataManager.getCurrentUser(action.token);
// // request logged-in user data
//UsersDataManager.getCurrentUser(action.token);
return Object.assign({}, state, { token: action.token });
//save token and logged-in user
return Object.assign({}, state, { token: action.token, currentUser: action.user });
case 'users/current-user':
// save logged-in user
return Object.assign({}, state, { currentUser: action.user });
//case 'users/current-user':
// // save logged-in user
// return Object.assign({}, state, { currentUser: action.user });
case 'users/current-user-error':
// discard user token
......
Supports Markdown
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