Skip to content

Instantly share code, notes, and snippets.

@Wicker25
Last active March 23, 2019 18:11
Show Gist options
  • Save Wicker25/2a7ade92ee31dbd061d9d96b0570c456 to your computer and use it in GitHub Desktop.
Save Wicker25/2a7ade92ee31dbd061d9d96b0570c456 to your computer and use it in GitHub Desktop.
import { observable } from 'mobx';
import { withStateTransition, stateTransition } from './StateTransition';
@withStateTransition
export class SessionStore {
constructor() {}
@observable accessToken = null;
@observable user = null;
@stateTransition('loading', 'idle')
async logInByAccessToken(accessToken) {
await this._setAccessToken(accessToken);
await this._fetchUser();
}
@stateTransition('loading', 'idle')
async logInWithFacebookAccessToken(facebookAccessToken) {
const response = await axios.get(SMUGL_API_FACEBOOK_TOKEN_CALLBACK, {
params: {
access_token: facebookAccessToken
}
});
await this._setAccessToken(response.data.content.token);
await this._fetchUser();
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment