Merge pull request #454 from outline/issue-448

Request auth on first load with existing token
This commit is contained in:
Jori Lallo
2017-11-28 23:00:00 -08:00
committed by GitHub
5 changed files with 50 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
// @flow
import { observable, action, computed, autorun } from 'mobx';
import { observable, action, computed, autorun, runInAction } from 'mobx';
import invariant from 'invariant';
import Cookie from 'js-cookie';
import localForage from 'localforage';
@@ -32,7 +32,20 @@ class AuthStore {
});
}
/* Actions */
@action
fetch = async () => {
try {
const res = await client.post('/auth.info');
invariant(res && res.data, 'Auth not available');
runInAction('AuthStore#fetch', () => {
this.user = res.data.user;
this.team = res.data.team;
});
} catch (e) {
// Failure to update user info is a non-fatal error.
}
};
@action
logout = () => {