Flow for all the files
This commit is contained in:
@ -1,25 +1,28 @@
|
||||
// @flow
|
||||
import { observable, action, computed } from 'mobx';
|
||||
import invariant from 'invariant';
|
||||
import { browserHistory } from 'react-router';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import type { User, Team } from 'types';
|
||||
|
||||
const USER_STORE = 'USER_STORE';
|
||||
|
||||
class UserStore {
|
||||
@observable user;
|
||||
@observable team;
|
||||
@observable user: ?User;
|
||||
@observable team: ?Team;
|
||||
|
||||
@observable token;
|
||||
@observable oauthState;
|
||||
@observable token: ?string;
|
||||
@observable oauthState: string;
|
||||
|
||||
@observable isLoading;
|
||||
@observable isLoading: boolean = false;
|
||||
|
||||
/* Computed */
|
||||
|
||||
@computed get authenticated() {
|
||||
@computed get authenticated(): boolean {
|
||||
return !!this.token;
|
||||
}
|
||||
|
||||
@computed get asJson() {
|
||||
@computed get asJson(): string {
|
||||
return JSON.stringify({
|
||||
user: this.user,
|
||||
team: this.team,
|
||||
@ -42,7 +45,11 @@ class UserStore {
|
||||
return this.oauthState;
|
||||
};
|
||||
|
||||
@action authWithSlack = async (code, state, redirectTo) => {
|
||||
@action authWithSlack = async (
|
||||
code: string,
|
||||
state: string,
|
||||
redirectTo: ?string
|
||||
) => {
|
||||
if (state !== this.oauthState) {
|
||||
browserHistory.push('/auth-error');
|
||||
return;
|
||||
@ -56,6 +63,10 @@ class UserStore {
|
||||
return;
|
||||
}
|
||||
|
||||
invariant(
|
||||
res && res.data && res.data.user && res.data.team && res.data.accessToken,
|
||||
'All values should be available'
|
||||
);
|
||||
this.user = res.data.user;
|
||||
this.team = res.data.team;
|
||||
this.token = res.data.accessToken;
|
||||
|
Reference in New Issue
Block a user