mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
38 lines
861 B
JavaScript
38 lines
861 B
JavaScript
'use strict';
|
|
|
|
import alt from '../alt';
|
|
import UserFetcher from '../fetchers/user_fetcher';
|
|
|
|
|
|
class UserActions {
|
|
constructor() {
|
|
this.generateActions(
|
|
'updateCurrentUser',
|
|
'deleteCurrentUser'
|
|
);
|
|
}
|
|
|
|
fetchCurrentUser() {
|
|
return UserFetcher.fetchOne()
|
|
.then((res) => {
|
|
this.actions.updateCurrentUser(res.users[0]);
|
|
})
|
|
.catch((err) => {
|
|
console.logGlobal(err);
|
|
this.actions.updateCurrentUser({});
|
|
});
|
|
}
|
|
|
|
logoutCurrentUser() {
|
|
return UserFetcher.logout()
|
|
.then(() => {
|
|
this.actions.deleteCurrentUser();
|
|
})
|
|
.catch((err) => {
|
|
console.logGlobal(err);
|
|
});
|
|
}
|
|
}
|
|
|
|
export default alt.createActions(UserActions);
|