Created
February 19, 2018 15:34
-
-
Save schovi/c90d0450aa4ae11b5ae64c9d0ff5c0d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Auth0 from '...' | |
class Auth0Store { | |
@observable authenticating = true | |
@observable profile = null | |
constructor() { | |
this.profile = Auth0.currentProfile | |
Auth0.on('authenticated', this.authenticatedDone) | |
} | |
@action() { | |
this.authenticating = false | |
} | |
} | |
export default new Auth0Store() | |
// In my global store I will have | |
import Auth0Store from '...' | |
class Store { | |
auth = Auth0Store | |
} | |
export default new Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file auth0_store.js | |
const Auth0Store = types.model('Auth0Store', { | |
authenticating: true, | |
profile: types.maybe(types.map({...})) | |
}).actions(self => { | |
return { | |
authenticated() {self.authenticating = false} | |
} | |
}) | |
// file store.js | |
const Store = types.model('Store', { | |
auth: Auth0Store | |
}) | |
// file state.js | |
import Auth0 from '...' | |
const state = Store.create({ | |
auth: Auth0.currentProfile | |
}) | |
Auth0.on('authenticated', () => { | |
state.auth.authenticated() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment